Created
January 6, 2022 05:43
-
-
Save harendra21/8c30ecebb912976e535a6a87947a574b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment