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


#1



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

https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/4?curriculum_id=4f89dab3d788890003000096#


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: ")


#2

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

#3

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