-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2b.py
More file actions
34 lines (31 loc) · 854 Bytes
/
2b.py
File metadata and controls
34 lines (31 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def display_menu():
print("Welcome to number conversion")
print("1. Binary to Decimal")
print("2.Octal to hexadecmial")
print("3. Exit")
def bin_to_dec():
bin_num=input("Enter the binary number to be converted")
try:
dec_num = int(bin_num, 2)
print("Decimal equivalent",dec_num)
except ValueError:
print("Error")
def oct_to_hexa():
oct_num=input("Enter the octal number to be converted")
try:
dec_num=int(oct_num, 8)
hex_num=hex(dec_num)
print("The hexadecimal equavilent",hex_num)
except ValueError:
print("Error")
while True:
display_menu()
choice=input("Enter your choice")
if choice=='1':
bin_to_dec()
elif choice=='2':
oct_to_hexa()
elif choice=='3':
break
else:
print("Enter a valid input ")