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 Set symmetric_difference_update()
Python Tuple
Python String zfill()
Python Program to Check Leap Year
Python Program to Generate a Random Number
Python ord()
Python strftime()
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Find the Factorial of a Number
Python Set update()
Python Set issubset()
Python String rstrip()
Python Set isdisjoint()
Python Program to Find ASCII Value of Character
Python Program to Get Line Count of a File
Python Object Oriented Programming
Python Errors and Built-in Exceptions
Python List reverse()
Python Program to Remove Duplicate Element From a List
Python Program to Get a Substring of a String
Python Global Keyword
Python Set symmetric_difference()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Count the Number of Digits Present In a Number
Python type()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Find Armstrong Number in an Interval
Python Program to Find Factorial of Number Using Recursion
Python @property decorator
Python frozenset()
Python Program to Check If Two Strings are Anagram
Python Namespace and Scope