Simple errors - more efficient way?


#1


https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/4?curriculum_id=4f89dab3d788890003000096#

I feel that

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

seems inefficient. I first tried while choice != 'y' and 'n' which didn't work but then I remembered that
for the 'and' condition both would need to be FALSE to have FALSE as a result.

Is there any other way to make this more efficient? in this case there are only 2 options, y and n but if there would be let's say 10 options, things would get inefficient really fast.


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


#2

i think, for two options this is the best solution, if you have more you could do something like:

choice = raw_input('Enjoying the course? (y/n)')
options = ['a','b','c','d','e','f','g','h']

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

#3

very good and simple!! that I didn't think of that. I honestly was thinking to use a list somehow and you showed me the way. thank you Sir :slight_smile:


#4