+ 1
Help me please.How in this code to do, if the dialled number is not the binary then print"the dialed number is not binary"Python
n=input('input binary number:') s=hex(int(n, 2)) print(s) https://code.sololearn.com/c18C5S4q5o36/?ref=app
2 Answers
+ 2
try:
s = hex(int(a, 2))
except:
s = "Is not binary"
==== or it:
if a.replace("0", "").replace("1", "") == "":
s = hex(int(a, 2))
else:
s = "number is not a binary"
print(s)
+ 1
thank you very much