lundi 22 février 2021

Why is my if-elif-else statement always returning the same answer?

Background:

I'm experimenting with while loops and I just made a simple program nested in a while loop.

Code:

while True:
    userinput = input("Is nem jeff? ")
    if userinput == "y" or "yes" or "Y" or "Yes":
        print ("YAY!")
    elif userinput == "n" or "no" or "N" or "No":
        print ("das sad :(")
    else:
        print ("wrong input")
        break

Problem:

My program should be looping until the user types in an invalid input, but instead, it always returns the value nested in the if statement, no matter what I type in. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire