File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ ####################################################################################################
2
+
3
+ # Question
4
+ # Write a Python script that reads any integer and asks the user to choose which option to convert:
5
+ # 1 for Binary
6
+ # 2 for Octal
7
+ # 3 for Hexadecimal
8
+
9
+ ####################################################################################################
10
+ num = 0
11
+ num = int (input ("\n Digit an integer positive or -1 to finish: " ))
12
+
13
+ while num != - 1 :
14
+ print ("""
15
+ Choose one of the bases to convert:
16
+
17
+ [ 1 ] convert to BINARY
18
+ [ 2 ] convert to OCTAL
19
+ [ 3 ] convert to HEXADECIMAL
20
+ """ )
21
+
22
+ option = int (input ("Your choose: " ))
23
+
24
+ if option == 1 :
25
+ print (f"\n { num } converted to BINARY is { bin (num )[2 :]} " )
26
+ elif option == 2 :
27
+ print (f"\n { num } converted to OCTAL is { oct (num )[2 :]} " )
28
+ elif option == 3 :
29
+ print (f"\n { num } converted to HEXADECIMAL is { hex (num )[2 :].upper ()} " )
30
+ else :
31
+ print ("\n #### Invalid option. Try again. ####" )
32
+
33
+ num = int (input ("\n Digit an integer positive or -1 to finish: " ))
34
+
35
+ print ("Bye!!!" )
36
+ ####################################################################################################
You can’t perform that action at this time.
0 commit comments