Loops, 4.Simple error


#1

Hi! With this code below it printed 20times " Sorry, I didn’t catch that. Enter again: "
Can someone help me understand what’s wrong with the code?

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

#2

Is your code properly formatted like this?

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

And also in this instance it would be better to use the or operator instead of the and operator because you want to keep asking the user based on two conditions.


#3

Please look at your code, you have smart quotes in there because you copy pasted from the forum.

why would we want or? if the user then enters valid input, we get True or False, which is true, the loop keeps running

@charlinegoyet, your code is fine. Make sure to enter y (n is also possible). If that doesn’t work, refresh the page


#4

After I connected the following day, I retried and it worked. I had try to
refresh the page that day but didn’t work.
Now it’s fine. Thank you !

Charline Goyet


#5

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