Simple errors: while not in ["y", "n"] doesnt work


Hi all. The code works fine but is not accepted as answer, but I thin it should. Or how am I wrong?

choice = raw_input('Enjoying the course? (y/n)')
while not choice in ["y","n"]:  # Fill in the condition (before the colon)
  choice = raw_input("Sorry, I didn't catch that. Enter again: ")
Does your code accept anything other than "y" and "n"?


Precedence means not will be evaluated first. not choice will be False assuming there is some input.

choice not in

Now choice is not evaluated by not, but in [...] is.


oh, of course, thanks :slight_smile:



>>> not 'a' in 'b'
>>> (not 'a') in 'b'
TypeError, or False if ['b'] is used instead

Your code is fine (though I’d prefer the not in operator)
The submission test doesn’t test the behaviour of your code in this case, instead it looks at the text which is evidently not reliable.


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