Code isnt working


#1

hi can you help me. this is my 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: ")

it isnt excepting n, when i type n it says that it didnt catch that and to try again


#2
while choice != 'y' and choice != 'n'

The 'n' can't be a hanging string, it has to have a variable assigned to it.


#3

@mohlabani

Or you can use not in syntax which is a little more succinct.

EXAMPLE:

if choice not in ('y', 'n'):
    print("Not in")

And this should be extremely easy to understand because it reads just as you what you would actually do.

EDIT:

I would also try to keep the == and != operators strictly to the math part and use the other comparison operators as I have when dealing with strings and such. Though on occasion you may have to use the strictness of == in your code with strings and such.