-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinary to decimal.py
30 lines (28 loc) · 1.18 KB
/
Binary to decimal.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
while True:
while True:
try:
b_num = list(input("\nInput a binary number:"))
except ValueError:
print("\nPlease enter only number")
else:
break
value = 0
for i in range(len(b_num)):
digit = b_num.pop()
if digit == '1':
value = value + pow(2, i)
print("\nThe decimal value of the number is",str(value) +'.')
while True:
Repeat=input("\nDo you want to calculate again?\n\nYes or No:")
Repeat=Repeat.lower()
if Repeat not in ["yes","y","no","n"]:
print("\nPlease select correct option")
else:
break
if Repeat in ["yes","y"]:
continue
else:
if Repeat in ["no","n"]:
print("\n-----Thank you for using-----")
input()
break