In this python tutorial, you will see how we can create that convert a binary number to a decimal number and do the vice versa in python. It is just simple mathematics that you should know.
You should Also Read: Decimal to Binary Converter in tkinter python
Decimal to the binary converter in Python
Below is the python code that helps us convert decimal to binary and vice versa. Run the following code in your python ide and you will see the result.
try:
menu = int(input("Choose an option: \n 1. Decimal to binary \n 2. Binary to decimal\n Option: "))
if menu < 1 or menu > 2:
raise ValueError
if menu == 1:
dec = int(input("Input your decimal number:\nDecimal: "))
print("Binary: {}".format(bin(dec)[2:]))
elif menu == 2:
binary = input("Input your binary number:\n Binary: ")
print("Decimal: {}".format(int(binary, 2)))
except ValueError:
print ("please choose a valid option")
Related Python Projects
- Encrypt Files in Python
- Finding IP Address of a Website in Python
- Sending Email in Python
- Extract all links from a website in python
- Add Watermark to an Image in Python
- Random Password Generator
- Convert a json file to a csv file in python
- Write hello world in Python
- Create Analog Clock with Python Turtle Module
- Create an Alarm Clock With Python - Python Project
- Create an Amazing Art With Python Turtle - Pickachu Character
- How to Create Decimal to Binary Converter with tkinter Python
- Python Turtle Project - Create Doraemon Character
- Python Will Recommend you A Movie Name
- Search a String Inside a File in Python
Summary and Conclusion
In this python tutorial, you have seen how we can create a python project that conversion of numbers system. If you have any questions please let us know in the comment section.