python - Error message shows even when answer is valid -
this question has answer here:
- how test 1 variable against multiple values? 16 answers
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
Post a Comment