Simple errors



this is the code I wrote. The loop execution is not ending and I cannot stop it

where am I wrong?
thank you for your help

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

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


if the user enters something valid, like y, then we get:

while false or true:

false or true is true, so the loop keeps running. Look at this example below:

true or true # true
true or false # true
false or false # false
true and true # true
true and false # false
false an false # false

i hope this tells you which operator you should use. Think about what happens when the user enters something (in)valid with the difference operators


thanks, this is meaning that I should use AND ?


yes, i added some more to my answer.

in case of invalid input by user using and would result in the following:

true and true, which is true, so the loop keeps running

if the user enters something valid, we get:

false and true, which is false, the loop exits, which it should, given the user entered something valid


thank you very much for your help


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