-1

I need to check if the input is correct, if not repeat the input process, but the code I use doesn't recognise the correct input as a correct input well. Please give me a solution. I'm a beginner in python.

cat_behaviour= []

print("\nIs the cat (A)ggressive or (F)riendly?\n")
behaviour = input().upper()

while not behaviour == 'A' or not behaviour == 'F':
    print("You have entered a wrong input. Please enter A for aggressive or F for Friendly")
    behaviour = input().upper()
    
cat_behaviour.append(behaviour)
  • 2
    Change `or` to `and` - if `not behavior == 'A'` is false (because `behavior == 'A'`), then `not behavior == 'B'` is necessarily true, so it'll always be true with an `or` – Mathias R. Jessen Oct 06 '21 at 12:23
  • 1
    If `behaviour` is "A", then it cannot also be "F", so the way you have phrased that condition one **or** the other will always be true… – deceze Oct 06 '21 at 12:24

1 Answers1

2
behaviour = input().strip().upper()

while behaviour not in "AF":
    ...

The .strip() will make sure that you are not getting any extra spaces, or end of line characters. The changed while condition is just for easier understanding. Your issue is, that you are using or instead of and (so it would only exit if the character is both A and F at the same time).

Mahrkeenerh
  • 1,104
  • 1
  • 9
  • 25