0

Hi I'm new to python and I'm having some trouble with logical operators. In the code I want the user to input one of three choices A, S , or D and reject anything else. The problem Im having is that when I input A, S, or D it still prints out Invalid Input.

guess = input("Lower (a), Same (s), Higher (d): ")

    if guess != "a" or "s" or "d":
        print ("Invalid Input")

Im using python version 2.7 if that helps

1 Answers1

0

Here or short circuit operator compares the two True values + the condition guess != 'a' (Because non empty values evaluate to True in Python), so use not in:

guess = input("Lower (a), Same (s), Higher (d): ")
if guess not in ['a','s','d']:
    print("Invalid Input")
Wasif
  • 14,755
  • 3
  • 14
  • 34