python - Error message shows even when answer is valid -


this question has answer here:

this first course in coding , don't know how use file=sys.stderr correctly.

i trying y or n input user , have error message show when answer neither of those.

this code:

aches = input("aches (y/n): ")  if aches != 'y' or 'n':  print ("error!",file=sys.stderr) 

aches= aches.casefold()

thank you!

it's if aches != 'y' , aches != 'n':.
if aches != 'y' or 'n' evaluated if (aches != 'y') or ('n') == if (aches != 'y') or true.
guess you're looking if aches not in ['y', 'n']:.
better approach if aches.lower() not in ['y', 'n']:, not consider 'y' , 'n' error.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -