Skip to content

Commit 179eed1

Browse files
authored
Merge pull request #8 from Sleepy4k/7-clean-up-convertion-func
7 clean up convertion func
2 parents 8708eb0 + a560869 commit 179eed1

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

main.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,29 @@ def error(err):
4646
print(err)
4747
separator()
4848
choice = input("Do you want to continue? [yes/no] : ")
49-
logic() if choice.lower() in ["yes", "y"] else exit()
49+
if choice.lower() in ["yes", "y"]:
50+
logic()
51+
elif choice.lower() in ["no", "n"]:
52+
exit()
53+
else:
54+
error("Invalid choice")
5055

5156
# Convertion
5257
def convertion(base, data):
5358
try:
5459
if base == Base.DECIMAL:
5560
decimal = int(data)
56-
binary = bin(decimal)[2:]
57-
octal = oct(decimal)[2:]
58-
hexadecimal = hex(decimal)[2:]
5961
elif base == Base.BINARY:
6062
decimal = int(data, 2)
61-
binary = data
62-
octal = oct(decimal)[2:]
63-
hexadecimal = hex(decimal)[2:]
6463
elif base == Base.OCTAL:
6564
decimal = int(data, 8)
66-
binary = bin(decimal)[2:]
67-
octal = data
68-
hexadecimal = hex(decimal)[2:]
6965
elif base == Base.HEXADECIMAL:
7066
decimal = int(data, 16)
71-
binary = bin(decimal)[2:]
72-
octal = oct(decimal)[2:]
73-
hexadecimal = data
67+
else:
68+
error("Invalid base")
69+
binary = bin(decimal)[2:]
70+
octal = oct(decimal)[2:]
71+
hexadecimal = hex(decimal)[2:]
7472
return (decimal, binary, octal, hexadecimal)
7573
except ValueError:
7674
error("System has value error")
@@ -88,7 +86,7 @@ def confirmation(base):
8886
elif choice.lower() in ["no", "n"]:
8987
logic()
9088
else:
91-
print("Invalid choice")
89+
error("Invalid choice")
9290

9391
# Result
9492
def result(decimal, binary, octal, hexadecimal):

0 commit comments

Comments
 (0)