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 Find Sum of Natural Numbers Using Recursion
Python Function Arguments
Python Program to Convert Two Lists Into a Dictionary
Python slice()
Python Program Read a File Line by Line Into a List
Python Program to Get a Substring of a String
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Statement, Indentation and Comments
Python Variables, Constants and Literals
Introduction to Scientific Programming with Python - Joakim Sundnes
Python String lstrip()
Python Program to Check Leap Year
Python Custom Exceptions
Python Set isdisjoint()
Python List copy()
Python Errors and Built-in Exceptions
Python String endswith()
Python pass statement
Python super()
Python input()
Python Set difference_update()
Python Keywords and Identifiers
Python List insert()
Python Inheritance
Python datetime
Python Program to Print Hello world!
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Illustrate Different Set Operations
Python String split()
Python Program to Copy a File
Python RegEx
Python Program to Create a Countdown Timer