Why I can't use "OR" instead of "AND"


#1

for this exercise, could you please help me to explain why I can't use "OR" instead of "AND" in the while condition testing. Since either 'n' or 'y' is ok to exit the loop?

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

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

Simple Errors Loops
#2

We can use or but need to change the operators from != (not equal to) to == (equal to).

while not (choice == 'y' or choice == 'n'):

This will fail when choice is one of y or n. We cannot write:

while False:

since it will never run the loop.

while False:
    print "oops!"
    break
else:
    print "loop did not run"
loop did not run

#3

ah ok. Thank mtf. :slight_smile:
I misunderstood the while condition test.
Topic closed.


#4