In this program, you will learn to convert decimal number to binary using recursive function.
o understand this example, you should have the knowledge of the following Python programming topics:
Decimal number is converted into binary by dividing the number successively by 2 and printing the remainder in reverse order.

Source Code
# Function to print binary number using recursion def convertToBinary(n): if n > 1: convertToBinary(n//2) print(n % 2,end = '') # decimal number dec = 34 convertToBinary(dec) print()
Output
100010
You can change the variable dec in the above program and run it to test out for other values.
This program works only for whole numbers. It doesn’t work for real numbers having fractional values such as: 25.5, 45.64 and so on. We encourage you to create Python program that converts decimal numbers to binary for all real numbers on your own.
Related posts:
Python Program to Merge Mails
Python Dictionary items()
Python Inheritance
Python Namespace and Scope
Python pow()
Python List index()
Python map()
Python Program to Check If a String Is a Number (Float)
Python Program to Add Two Numbers
Python Program to Differentiate Between del, remove, and pop on a List
Python pass statement
Python break and continue
Python String isdecimal()
Python List reverse()
Python String rindex()
Python object()
Python String istitle()
Binary Numbers in Java
Python List clear()
Python Program to Print Output Without a Newline
Python Program to Represent enum
Python frozenset()
Python dir()
Python open()
Python Program to Check Leap Year
Python File I/O Operation
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Directory and Files Management
Python Get Current time
Python Program to Solve Quadratic Equation
Python Program to Convert Bytes to a String