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 Create a Countdown Timer
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Set update()
Python Program to Make a Flattened List from Nested List
Python vars()
Python String isidentifier()
Python exec()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python String splitlines()
Python len()
Python List index()
Python list()
Python Machine Learning - Sebastian Raschka
Python Program to Find Numbers Divisible by Another Number
Python Program to Convert String to Datetime
Python @property decorator
Python Program to Find Sum of Natural Numbers Using Recursion
Python Set symmetric_difference_update()
Python Set copy()
Python Program to Check If a String Is a Number (Float)
Python String isnumeric()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String endswith()
Python String split()
Python hash()
Python Program to Add Two Matrices
Python timestamp to datetime and vice-versa
Python Program to Print Output Without a Newline
Python String center()
Python String rsplit()
Deep Learning with Python - Francois Chollet
Python String ljust()