Skip to content

Instantly share code, notes, and snippets.

@harendra21
Created January 6, 2022 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harendra21/8c30ecebb912976e535a6a87947a574b to your computer and use it in GitHub Desktop.
Save harendra21/8c30ecebb912976e535a6a87947a574b to your computer and use it in GitHub Desktop.
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