Oct-30-2022, 09:27 PM
I'm writing my first python program as a number guessing game. I am trying to loop a question until a 'yes' or 'no' response is given but am having trouble figuring it out.
'''
When I answer 'yes', the program works fine and continues how I want it:
When I answer 'no', the program exits and works how I want it:
When I answer anything else, I want it to ask "Sorry, please type 'yes' or 'no" and continue asking that question until a 'yes' or 'no' input is received. However, it just continues with the program.
I would like it to keep asking the question until a 'yes' or 'no' is received, but I can't quite figure it out. I would appreciate any help!
'''
response = input("Do you want to try a guessing game?: [yes or no]") while response != "yes" or "no": if response =="yes": print("Great, let's get started! Guess a number from 0-20") break elif response == "no": print("Okay, see you later!") exit() else: print("Sorry, please type 'yes' or 'no':") break'''
When I answer 'yes', the program works fine and continues how I want it:
When I answer 'no', the program exits and works how I want it:
When I answer anything else, I want it to ask "Sorry, please type 'yes' or 'no" and continue asking that question until a 'yes' or 'no' input is received. However, it just continues with the program.
I would like it to keep asking the question until a 'yes' or 'no' is received, but I can't quite figure it out. I would appreciate any help!