4. Simple error - Solution not being accepted


#1


Getting the following error message but would not know what else the solution could possibly accept:

Oops, try again. Does your code accept anything other than "y" and "n"?

Is this a simple case of the checker script looking for a boolean expression?


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

valid_choices = ['y', 'n']

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


#2

Hi, @netpro30902,

EDITED: See reply, below, by @ionatan.


#3

I'd rephrase to:

while choice not in valid_choices:

But that's just a cosmetic difference, same behaviour

Yes, the submission test is probably looking for something specific, the instructions might be asking for something slightly different from what you're doing and that might be what's tested.

If you've got a link to the exercise I'd be able to figure out what that something is if you're not able to spot it yourself in the instructions.

@appylpye found the exercise, it's looking for "not in" or a few other options, but not the one you used. The one you used is correct, but doesn't read very nicely which is probably why the not in operator exists (I find that NOT is a fast way to make something very difficult to read if put in a bad place or is used more than once)


#10

tthanks for the reply. I guess my main issue here is that while my code is perfectly fine sans the (valid) cosmetic change you suggested, the excercise is not about boolean operators but about while loops so the script shouldn't be so strict.

Having said that, looking through the other posts about this excercise in the forums, it seems my approach would solve alot of the confusion out there as other solutions where trying to use boolean operators which in turn I find hard to read and it seems I'm not the only one. A main strength of Python seems to be that it's closer to english than other languages and thus way easier to read and the code speaks for itself if done properly in alot of cases.


#11

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