jeudi 2 mai 2019

Is there a way for an else statement to have a loop until an if or else if statement is meant [duplicate]

This question already has an answer here:

I'm writing a new code for a quiz game and I am trying to ask them "Would you like to play?" and if they answer anything other then yes or no I would like it to print "That is not a valid answer" then have a loop until the player correctly answers yes or no.

I have tried to solve this and google it but I am still learning python and can't seem to find an answer. I think you must have to put, while True, after the else command but after that, I am not sure what.

choice = input ("Do you want to play?")
if choice == "yes" 
    print("Great!")
elif choice == "no" 
    print("Goodbye.")
else:
    print("Please answer yes or no.")

I expect the else statement to take the player back to start but instead the code finishes

Aucun commentaire:

Enregistrer un commentaire