Simple errors


choice = raw_input('Enjoying the course? (y/n)')

while choice!="n" and choice!="y": # Fill in the condition (before the colon)
choice = raw_input("Sorry, I didn't catch that. Enter again: ")

I don't get it. isn't while supposed to be:

while choice!"n" OR choice="y"!?!?
Why is it and? It's supposed to be or that it doesnt equal y or doesnt equal n.

can someone explain thiss to me


Agree with me that a while loop runs, as long as the condition evaluates to True?

let's say we use or:

while choice!="n" or choice!="y":

and i input y, then choice!="n" is true, and choice!="y" is false. So we have True and False, when using or, if one of the condition is True, it will evaluate to True, so the loop will run again, oops.

Now, if we used and:

while choice!="n" and choice!="y":

if i input y, choice!="n" is True, and choice!="y" is False. True and False evaluate to False, which is what we want. Since we want to stop the loop (the user input is valid)

now, again with and:

while choice!="n" and choice!="y":

what if i put something wrong? For example x, then both condition are True, True + True = True, so the loop will run again to get valid user input.

I know this feels weird, and counter intuitive, but i hope this helps :slightly_smiling:


This helped me a lot, thanks for the explanation.