Simple Errors (Am I doing it Right?)


I typed in 'y' and 'n' and the code keeps going and going>

I not sure what is going to happen, am I doing it right?

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

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


In the above, the string, 'n' casts to True in a conditional expression, so this will always be True. False can never be an outcome of the whole expression.

choice != 'y' or choice != 'n'

Notice we have two distrinct expressions with two possible outcomes for each. That means False can be an outcome of the whole expression.


I typed in the correct code and it still keeps going. How do I close the loop? Am I supposed to close the loop?


Okay, now it comes down to logic. The or operator will find one case true when the other is false. Try using and. That way, when only one is false, the whole expression is false.


I got now, thank you!:blush:


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