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 reversed()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Deep Learning in Python - LazyProgrammer
Python List pop()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python ord()
Python hasattr()
Python Dictionary popitem()
Python Program to Find Armstrong Number in an Interval
Python Program to Solve Quadratic Equation
Python str()
Python Program to Create a Countdown Timer
Python sorted()
Python Program to Find the Largest Among Three Numbers
Python Program to Transpose a Matrix
Python dir()
Python oct()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Get File Creation and Modification Date
Python Package
Python for Loop
Python String isupper()
Python divmod()
Python frozenset()
Python Machine Learning - Sebastian Raschka
Python Program to Find the Factors of a Number
Python del Statement
Python abs()
Python setattr()
Python Program to Find ASCII Value of Character
Python Program to Find the Sum of Natural Numbers