4/19 loops


#1

this is my code i saw in other discussions and it should be correct according to the discussion
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: ")
and it gives the error
Traceback (most recent call last):
File “python”, line 3, in
NameError: name ‘y’ is not defined

here is the link to website if you all want to see thanks in advance
https://www.codecademy.com/courses/learn-python/lessons/loops/exercises/simple-errors?action=lesson_resume


#2

and also when i checked the answer it showed this:
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: ")
isnt this the same !


#3

If you compare the two versions you posted, no, they’re not the same

When you compare two pieces of text you should do it in such a way that even the smallest difference gets found. For short text you can do it by eye, for something longer you would need a program to do the comparison for you.

You’ve also got an error message explaining what the problem is, and where the problem was encountered

Nearly right isn’t enough when any difference makes it wrong! Gotta spot these things.


#4

The problem here is that you are comparing choice (the user input) with a variable --y-- that does not exist. In this case you want to compare choice with the string “y” and “n”. So, all you have to do is to put y and n in quotes.


#5

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