-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
34 lines (34 loc) · 1.01 KB
/
converter.py
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
# WAP to input a number in decimal and convert it to binary, octal, hexadecimal
print("Number System Converter")
print("""What do you want to do?
1. Convert Decimal to Binary
2. Convert Decimal to Octal
3. Convert Decimal to Hexadecimal""")
while True:
a = input("Enter your choice(1/2/3): ")
if a in ('1','2','3'):
b = int(input("Enter your decimal number here: "))
if a == '1':
print(b, 'in binary is', bin(b) [2: ])
exit("Thanks!")
elif a == '2':
print(b, 'in octal is', oct(b) [2: ])
exit("Thanks!")
else:
print(b, 'in hexadecimal is', hex(b) [2: ])
exit('Thanks!')
else:
print("Invalid input, retrying")
continue
'''
Output:
Number System Converter
What do you want to do?
1. Convert Decimal to Binary
2. Convert Decimal to Octal
3. Convert Decimal to Hexadecimal
Enter your choice(1/2/3): 2
Enter your decimal number here: 225
225 in octal is 341
Thanks!
'''