Simple errors


#1

Hi,

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


#2

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


#3

thanks, this is meaning that I should use AND ?


#4

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


#5

thank you very much for your help


#6

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