Help in Python
Off topic → Programming → Help in Python
SOLVED
Any input I put in will print out “Test 1”, and I don’t know why. This is a bit of code I simplified from a bigger project that is supposed to print out one of many statements based on an input. Can someone please explain?
q = input("Addition or Subtraction?: ")
if q == "addition" or "a":
print("Test 1")
elif q == "subtraction" or "s":
print("Test 2")
Note: This is Python 3.6.1
[EDIT by pep]: Added code brackets, didn’t touch anything else
If I’m not mistaken, code within conditionals (the prints) must be indented for it to work correctly.
if "a":
print("Test 1")
As “a” is “> 0” it counts as true
meaning that something or "a"
is always true.
Try to do if q == "addition" or q == "a":
instead. Possibly with parenthesis :P
@Yummy_ as far as I can tell it is indented properly?
Thanks, it works now.
Originally fixed by Logal this afternoon.
Mark as solved?