0
Bug?
Why does this code: x = input() if x == "Visa" or "Amex": print("accepted") Only output accepted no matter what the input is?
2 Réponses
+ 8
Because the if condition is wrong.
if (x == "Visa") or (x == "Amex"):
...
is the correct syntax.
You ask the computer: if the input is equal to Visa or if the string "Amex" is a value, which it is, so it's True every single time. Try the correct syntax and try also not to assume a bug
+ 5
if x=="Visa" or x=="Amex":
# Or
if x in ["Visa","Amex"]: