+ 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

22nd Nov 2017, 9:30 AM
Пиров Мустафо
Пиров Мустафо - avatar
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)
23rd Nov 2017, 7:28 AM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar
+ 1
thank you very much
23rd Nov 2017, 7:55 AM
Пиров Мустафо
Пиров Мустафо - avatar