Why I can't use y 'and' n?


#1

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

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

What is wrong with this? why I can't use y 'and' n? can someone explain it to me?


Simple errors
#2

Greetings guys, here's the solution that worked for me:

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

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


I had a bit of a hard time figuring it out, but I managed to complete the task once I reminded myself that thinking out of the box is what programing is.
Pay special attention to the conditions of the while loop, that's where the magic happens. :slight_smile:

I hope I helped
Kind Regards


#3

The magic here being that there will be no job offers. This needs to go back to the drawing board.

while choice not in 'yn':

However, this leads to repeated code for the raw_input, which suggests a do..while, something Python does not have. There is a way, though...

while True:
    choice = raw_input(" ... (y/n)")
    if choice.lower() in 'yn': break

#4

I don't know, I tested it several times, and it worked.
I really don't see what your problem is.
+ even if it leads to repeated code for the raw_input, you can always break the statement after the requirement is met :slight_smile: INNIT


#5

Of course it worked. If you are satisfied with that, then have at 'er.


#6

@mtf
I am curious as to what the three dots are representing here and why this works as a better choice.

not to mention thus far in the course I don't recall the .lower() being referenced in a lesson but, I may have some amnesia and don't remember.


#7

... simply represents the string you want to show the user, its not the relevant part of mtf's help, so he simply put some dots

lower is taught in string and console output, and you used it in pyglatin, and very likely at more places


#8

@stetim94
Thank you!
I knew I had a bit of amnesia. lol


#9

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