vendredi 18 octobre 2019

Python Loop - Valid Input

So I'm having some trouble with my loop at the beginning of my code asking the user if they want to play. How do I get it to replay the loop if the user types in an invalid response?

Below is what I have so far, but I'm stuck on where to go from here

play = input('Would you like to play the Guess the Number Game [y|n]?')
while play == 'y':
     play = True
if play == 'n':
     print ("No worries... another time perhaps... :)")
     exit()
else:
     print ("Please enter either 'y' or 'n'.")

Aucun commentaire:

Enregistrer un commentaire