Currently trying to write a code for my CS class, translating an 8 digit binary number to decimal. The code needs to exclude all digits not 0,1, as well as incorrect character length. The error is focusing on the else statement. My book doesn't cover my error, and my internet searches have the same result.
if re.match("01", binary):
#check for correct entry length
if len(binary == 8):
print(int(binary, 2)
else:
print("The entry must be 8 digits")
#^syntax error
else:
print("Only numbers 1 and 0 may be used")
Aucun commentaire:
Enregistrer un commentaire