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 Print Hello world!
Python Program to Randomly Select an Element From the List
Python Program to Find Factorial of Number Using Recursion
Python callable()
Python String lstrip()
Python del Statement
Python dir()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python super()
Python Program to Transpose a Matrix
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python repr()
Python Program to Find the Sum of Natural Numbers
Python Dictionary get()
Python staticmethod()
Python frozenset()
Python complex()
Python Set union()
Python Program to Convert Bytes to a String
Python Program to Count the Occurrence of an Item in a List
Python Set add()
Python sorted()
Python String isspace()
Python compile()
Python Objects and Classes
Python String islower()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python print()
Python Program to Generate a Random Number
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Global, Local and Nonlocal variables
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar