When I run this program like this:
jonathan = 15
anthony = 25
if (jonathan or anthony) >= 21:
print("They can enter the building together.")
else:
print("They are not allowed to enter the building together.")
It outputs: They are not allowed to enter the building together.
However, when I run the program like this:
jonathan = 15
anthony = 25
if (anthony or jonathan) >= 21:
print("They can enter the building together.")
else:
print("They are not allowed to enter the building together.")
It outputs: They can enter the building together.
I was under the impression that the placement of the variable in this conditional if statement didn't matter if I was using the or keyword, since a conditional test with the or keyword passes if either one of the variables pass the test.
I do notice however that when I run the program like this, where jonathan
is first again, and everything is included in the parentheses:
jonathan = 15
anthony = 25
if (jonathan or anthony >=21):
print("They can enter the building together.")
else:
print("They are not allowed to enter the building together.")
It outputs: They can enter the building together.
It would be greatly appreciated if one or more of you could explain to me the reasoning behind why the positioning of the variable & parentheses matters here in this condition with or.
I'm by no means an expert but from my point of view, it would probably be safest to use the last method where everything is in parentheses, including the >=21.
Thank you.