-5

I Am Not A Pro, I Have Not Been Programing For Long But Why Doesn't This Work?

door = input("I Have Found A Haunted House,Should I Go In?")

if door == "yes" or "Yes" or "YES":
    print("Ok! I Am Going In")

else:
    print("What?")


while door == "no" or "No" or "NO":
    print("Awwh Thats A Shame, I Was Getting Excited")
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
Raymonoir
  • 3
  • 5
  • 3
    What does "does not work" mean? – Marcin Dec 09 '13 at 19:04
  • Offtopic: I think you have ".title()" virus on your computer... ;) – mchfrnc Dec 09 '13 at 19:06
  • 2
    Do you really want to print that last message infinitely if the user enters "no"? – David Dec 09 '13 at 19:07
  • 1
    For reference: programming does not work like spoken language with conjunctions. You *must* explicitly say what each clause/condition applies to. "If I go to the store and buy milk" must be "If I go to the store and I buy milk". – thegrinner Dec 09 '13 at 19:08
  • 2
    "Not working" does **not** have a meaning. Either 1) the program raises an exception and you should post the **full** traceback, or 2) it gives an unexpected output, and you should post the output you get *and* the output you'd expect, or 3) the program gets stuck, which you didn't say. It'd be even better to provide a *minimal* working example that demonstrates the problem instead of the whole program. Next time be sure to provide this information because in this case the error was obvious, in other cases the best people *cannot* answer you without *at least* such information. – Bakuriu Dec 09 '13 at 19:10

1 Answers1

4

Don't worry, this is a very common mistake.

You need to use in here:

if door in ("yes", "Yes", "YES"):

Or, even better, str.lower:

if door.lower() == "yes":

The reason for this is that Python evaluates non-empty strings as being True. So, your code is actually being interpreted like this:

if (door == "yes") or ("Yes") or ("YES"):
#    True/False        True       True

As you can see, this if-statement will always pass.