I've got a simple piece of code that asks for user input and returns a boolean variable. In case the input was unacceptable, the user has the chance to correct herself. But the boolean gets properly updated only when the else part of the if-statement is not invoked. When it is, the function always returns False.
def tryAgain():
bol = False
print('Do you want to try again? (Y/N)')
answer = input('> ').lower()
if (answer == 'y' or answer == 'n'):
if answer == 'y':
bol = True
else:
print('Your answer could not be parsed')
tryAgain()
return bol
Aucun commentaire:
Enregistrer un commentaire