why wont this work? (python using or in an if statemt)
Go to solution
Solved by Alvin853,
That's not how
or
works. The == takes precedence over the or, so
total == 1 or 2
evaluates to
(3 == 1) or 2 false or 2
"or 2" doesn't mean anything to Python, so the 2 is converted to a boolean, which turns it into true, and true on any side of an "or" makes the whole thing true.
You need to write
total == 1 or total == 2
for it to work as expected

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now