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 int()
Python Dictionary pop()
Python len()
Python Program to Print Hello world!
Python Package
Python pass statement
Python String endswith()
Python Custom Exceptions
Binary Numbers in Java
Python float()
APIs in Node.js vs Python - A Comparison
Python Program to Reverse a Number
Python Dictionary update()
Python Program to Check Armstrong Number
Python Program to Capitalize the First Character of a String
Python String translate()
Python Dictionary values()
Python String rstrip()
Python sleep()
Python Multiple Inheritance
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Dictionary items()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Make a Flattened List from Nested List
Python Program to Print the Fibonacci sequence
Python Program to Find Armstrong Number in an Interval
Python Program to Convert Kilometers to Miles
Python String ljust()
Python Program to Add Two Matrices
Python String isidentifier()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey