Bug? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Bug?

Why does this code: x = input() if x == "Visa" or "Amex": print("accepted") Only output accepted no matter what the input is?

20th Aug 2022, 9:44 PM
Andrew
Andrew - avatar
2 Answers
+ 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
20th Aug 2022, 9:47 PM
Slick
Slick - avatar
+ 5
if x=="Visa" or x=="Amex": # Or if x in ["Visa","Amex"]:
20th Aug 2022, 9:49 PM
SoloProg
SoloProg - avatar