+ 11
The or operator is meant to link two Boolean statements, not two potential answers in a Boolean statement. something like if answer == 5 or answer == 6: would be what you're aiming for. What you're encountering is a quirk where many languages will take a non-Boolean value where a Boolean is expected, and evaluate anything non-zero as true.
18th Jun 2017, 4:28 AM
Jim
Jim - avatar
+ 5
Your first test evaluates the following: is input == 5; is 6 == True. And produces true if any of the conditions is met. Basically, it is always true, because any number that is not equal to 0 is considered to be True when converted into a boolean. For your code to work, the if test should be written like this: if input ==5 or input==6
18th Jun 2017, 6:59 AM
Agnius Bartninkas
Agnius Bartninkas - avatar
+ 1
you can do: answer = input("What is the secret? ") if answer == (5 or 6): print("Correct!") elif answer == 7: print("Aren't we all secretive, then?")
22nd Jun 2018, 12:42 PM
Sahil Danayak
Sahil Danayak - avatar