Python program to convert decimal to binary using recursion
In this python programming guide, we are going to learn to:
write a python program to convert decimal to binary using recursion
Program to convert decimal to binary in python
The python program to convert decimal to binary using recursion is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
if n > 1:
print(n%2, end = "")
if __name__ == "__main__":
number = int(input("Enter a number: "))
The output of python program to convert decimal to binary using recursion is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 7
Few important tips about this program
1. Here, we ask the user to enter a number and we type convert it to integer data type.
2. Then we call the function "decimal_to_binary" to convert the number to binary.
3. The function calls itself until the number itself becomes less than 1. We have used recursion here.
4. Python provides a bin() function whicn can directly convert a decimal number to binary.
Write a python program to convert decimal to binary using recursion snapshot:
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Full Stack Web Developer & Data Science Enthusiast
Page Views :
Published Date :