jeudi 24 décembre 2020

Understand unexpected behaviour of if/else statement | Always skips to else block [duplicate]

On the following code, I want it to split into the two options...answer ("yes", "sure", etc.) and it prints out: "ok great, here are the rules.." line.

Likewise, if you respond with anything else it will say "ok, later!".

Right now, the output is only saying "ok, later" and never runs the print in the if statement as if if was always False.

What am i doing wrong?

fname = input("Hey what's your first name? : ")
lname = input("Ok, what's your Last Name? : ")
print ("Hello  " + fname + " " + lname)

if input('Want to play Mad Libs?') == ("yes" or "Yes" or "sure" or "Sure" or "ok" or "Ok" or "OK"):
   print("Ok, Great!  The rules are simple; I am going to ask you for words like a noun, pronoun, adjective, verb, etc., and then you fill one in.  Hope you come up with something funny!") 
else:
    print("Ok, later!")
    exit()

Aucun commentaire:

Enregistrer un commentaire