4. Simple errors


#1

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 code is not working..can anyone tell me about the mistake.


#4

break the loop at the end.


#5

wat does it look like?


#6

this is what worked for me:

choice = raw_input('Enjoying the course? (y/n)')
y = "y"
n = "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: ")


#7

I had the same exact code, except for the quotation marks, and it didn't work either.

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


#8

the code my be like this..it's work for me..thanks for the break farzfarz

choice = raw_input('Enjoying the course? (y/n)')
y = "y"
n = "n"
while choice != y and choice != n:
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")
    break

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

Should work fine (it does for me). You shouldn't need to break the loop as when choice is equal to either "n" or "y", the statement then evaluates to false. (choice != 'y' and if you typed "y" at the prompt, that evaluates to false because "y" == "y" and statement is looking for "y" != "y") While loops only loop while the conditional statement is true (wow that sentence seems redundant)


#10

Hey there, (@joshuahappy0)

This code worked for me:

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

The task basically tells you what to do, I would recommend reading back over it.

Hope this helps,

~NocturnalDweller~


#11

The solutions suggested by you guys work but that's not what codecademy wants.
If you follow the code above using "break," you're only cheating the system. I tested it and discovered that even if you use another alphabet the system will still pass you because you already told the system to "break" regardless of your choice being the right or wrong one.
Your code should actually look like 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: ")
    choice == "n" and choice == "y"

#12

I didn't use break in my solution. @objectwhiz18499
You only learn break in a later task as well, I didn't even know about it till a few task later.

You don't actually need the last line in your solution to pass the task and codecademy doesn't ask for it.

~NocturnalDweller~


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

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

this code works to , ahh i see you guys look at the hint but im not haha


#14
choice = raw_input('Enjoying the course? (y/n)')
y = "y"
n = "n"
while choice != y and choice != n:
    choice = raw_input("Sorry, I didn't catch that. Enter again: ")

This is the correct version of code as you should not get out of the loop until you input y or n


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

Comrades, this worked for me, you just need to make choice a string and then all is well.


#16

you are beautiful trust me


#17

this worked for me

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

#19

are you using an indentation?
if not, press tab before choice = raw_input(blablabla)


#20

This is what worked for me. Oddly I felt like i had entered this several times, and kept getting the error, does your code accept anything other than n or y ? Now it seems to be working. I tired adding a break inside the while loop at the end, but it did not allow for a user to enter in answers other than n and y repeatedly. This code allows for the user to repeatedly enter other responses until they choose y or n.

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


#21

Questions for anyone. With this code, why does 'or' give an infinite loop?

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

#22

shouldn't we be using an 'or' statement ?
That's a different thing even that's not working


#23

I've been reading some comments. Most of you guys, create a variable for the answers. It is NOT wrong, but it is more work. You could also do write the code like that:

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