Simple errors


#1

Hello, I need help with this.

I wrote the following code:

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

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

and the answer on the window console showed my code work fine, but it won't let me go on to the next quiz.

What am I doing wrong. Please help.


#2

Logic... AND instead of OR.


#3

Thanks.

I tried both 'and' and 'or'.

The answers in the window console show either one works.

But the system still won't let me pass to the next quiz.

Is it a bug ?


#4

Not that I am aware of. This is a very old course.

Recall that while depends upon truthiness in its conditional expression or it either won't execute, or it will terminate.

NOT y OR NOT n

can be truthy when the input is not "y". That means the expression is short circuited and and the second operand doesn't even get looked at.

We need an expression that MUST not short-circuit on TRUE, meaning AND.

NOT y AND NOT n

This will short circuit on "y" or "n" as inputs (short circuits on FALSE).

Please post a link to the exercise if you are still stuck.


#5

Thank you.

It still does not work.

I have tried "and" (see below) and many other variations, but each time the "submit and save" button greys out and the screen freezes. Please help.

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

Lemonade


#6

Careful you do not interpret my pseudo-code directly. Syntax rules still apply...

while choice != 'y' and choice != 'n':

They are string literals, after all.


#7

Hello, thanks again for the prompt response.

That was one of the variations I tried. It does not work, the "save and submit" button remains grayed out when I try to respond to the y/n question on the windows console. I tried undoing and refilling the code, rebooting the computer, and reentering codecademy, none of that worked either.


#8

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