-
Notifications
You must be signed in to change notification settings - Fork 415
/
Copy pathnumber_base_converter.py
36 lines (28 loc) · 1.15 KB
/
number_base_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
35
36
####################################################################################################
# Question
# Write a Python script that reads any integer and asks the user to choose which option to convert:
# 1 for Binary
# 2 for Octal
# 3 for Hexadecimal
####################################################################################################
num = 0
num = int(input("\nDigit an integer positive or -1 to finish: "))
while num != -1:
print("""
Choose one of the bases to convert:
[ 1 ] convert to BINARY
[ 2 ] convert to OCTAL
[ 3 ] convert to HEXADECIMAL
""")
option = int(input("Your choose: "))
if option == 1:
print(f"\n{num} converted to BINARY is {bin(num)[2:]}")
elif option == 2:
print(f"\n{num} converted to OCTAL is {oct(num)[2:]}")
elif option == 3:
print(f"\n{num} converted to HEXADECIMAL is {hex(num)[2:].upper()}")
else:
print("\n #### Invalid option. Try again. ####")
num = int(input("\nDigit an integer positive or -1 to finish: "))
print("Bye!!!")
####################################################################################################