0

This is my first course in coding and I don't really know how to use file=sys.stderr correctly.

I am trying to get a y or n input from the user and only have the error message show when the answer is neither of those.

This is my code:

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

aches= aches.casefold()

Thank you!

sj13
  • 11
  • 3

1 Answers1

1

It's if aches != 'y' and aches != 'n':.
if aches != 'y' or 'n' is evaluated to if (aches != 'y') or ('n') == if (aches != 'y') or true.
I guess what you're looking for is if aches not in ['y', 'n']:.
A better approach would be if aches.lower() not in ['y', 'n']:, which will not consider 'Y' and 'N' as error.

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55