Why does the code work? (Loops, 4 - Simple Errors)


So my problem is a bit different. I'm not able to understand why the code is working.


When I enter "y" or "n" as a response, the whole condition choice != "y" and choice != "n" becomes False, and hence the while loop stops. But if that logic is true, then it should stop even if any response other than "y" or "n" is entered, since that would make the condition false too. I'm perplexed!

while choice != "y" and choice != "n":
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")


Not so. It will be true in all cases except when choice is y or choice is n.

T and T  =>  True

T and F  =>  False

F and T  =>  False


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.