4. Simple errors


#1

I'm working on Simple Errors: https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/4?curriculum_id=4f89dab3d788890003000096#

This is the error I get: Oops, try again. Does your code accept anything other than "y" and "n"?

I'm seeing others have luck when using the following code:

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

while choice != "y" and "n":  
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")

but I'm getting the error whenever I input a y or n. Do I need to create a few if loops to account for those particular inputs?

Thnx for the help!


#2

Keep in mind that you're not writing in English, what does the and operator do? What would cause "n" to be compared to choice in your code?

You need to create an expression that correctly tells correct input apart from incorrect input. Test it.


#3

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

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

This is working


#4

This helped, thanks!


#5

This was the code I ended up with when I started thinking about whether choice was in some relationship to n. Thanks for your help!


#6

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