while userinput != "yard" or userinput != "gym" or userinput != "basement" or userinput != "cell" or userinput != "showers" or userinput != "outside":
            print "Enter 'yard' or 'gym' or 'basement' or 'cell' or 'showers' or 'outside' to search them."
            if userinput == "yard":
            elif userinput == "gym":
            elif userinput == "basement":
            elif userinput == "cell":
            elif userinput == "showers":
            elif userinput == "outside":

It doesn't go into an infinite loop when I enter the prompts listed but once I hit enter it goes into an infinite loop. Why is that? I tried to figure out why but I'm having a hard time. Thanks


closed as off-topic by David Richerby, Ran G., Rick Decker, D.W. Nov 8 '15 at 22:39

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – D.W.
  • "This question does not appear to be about computer science, within the scope defined in the help center." – David Richerby, Ran G., Rick Decker
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ "yard" != "gym" so userinput != "yard" or userinput != "gym" or ... is always True. ​ ​ $\endgroup$ – user12859 Nov 8 '15 at 17:03
  • 1
    $\begingroup$ I don't think "please debug my code" is on-topic anywhere on the Stack Exchange network. $\endgroup$ – David Richerby Nov 8 '15 at 17:54

Your condition is:

while userinput != "yard" or userinput != "gym" or ...

By using De Morgan's law it is equivalent to:

while !(userinput == "yard" and userinput == "gym" and ...)

As userinput can only have a single value it cannot be equal to both "yard" and "gym" meaning that the expression in the brackets is always False making the whole condition !False = True no matter the value of the userinput.

I am unsure of what end_game() does so I cannot comment if it can break out of the loop or not.


Not the answer you're looking for? Browse other questions tagged or ask your own question.