mercredi 19 août 2020

Python throws a syntax error for else: statement

def ask():
    while True:
        try:
            num = int(input("Enter an integer:"))
        except:  
            print('Not a number, please try again')
        continue
        else:
            print('Thats a valid number!')
            break
        finally:
            print('All done')

I get this error-I checked and rechecked indentaion, but still not working

File "<ipython-input-46-ff8c841c59c4>", line 8
    else:
       ^
SyntaxError: invalid syntax

Aucun commentaire:

Enregistrer un commentaire