Skip to content

Commit 65dce60

Browse files
Merge pull request souravjain540#126 from ViniViniAntunes/number_base_converter
Number base converter
2 parents 6438338 + dceab67 commit 65dce60

File tree

2 files changed

+36
-99
lines changed

2 files changed

+36
-99
lines changed

arabic_to_roman_numbers.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

number_base_converter.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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("\nDigit 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("\nDigit an integer positive or -1 to finish: "))
34+
35+
print("Bye!!!")
36+
####################################################################################################

0 commit comments

Comments
 (0)