Skip to content
Advertisement

How can I have my input be typed out again via using while loops and if statements?

So i have this simple problem and I am not so sure what to do even after trying it for quite sometime.

combinations = ["rock","papers","scissors"]
ask = str(input("Do you want to play rock papers scissors?"))
while ask:
    if ask.lower() == "yes":
        print("ok")
        break
    elif ask.lower() == "no":
        print("okay :(")
        break
    else: 
        ask = input("So is it a yes or no ?!")
        break

my issue is that I am not so sure what to type such that my input user has to type either yes or no instead of typing something else. Additionally, when I tried to run the program, when I typed yes/no it jumped straight to the else statement instead of the if statement.. someone pls help :( (am just a noob programmer)

Advertisement

Answer

I would remove the break in the else statement so that your program keeps looping until the user inputs yes or no.

combinations = ["rock","papers","scissors"]
ask = str(input("Do you want to play rock papers scissors?"))
while ask:
    if ask.lower() == "yes":
        print("ok")
        break
    elif ask.lower() == "no":
        print("okay :(")
        break
    else: 
        ask = input("So is it a yes or no ?!")
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement