Feb-13-2022, 10:38 PM
You don't understand how "or" works. This is pretty common with new Python programmers. I will demonstrate how "or" works with some code.
Lets try Player = "P"
From the documents : https://docs.python.org/3/library/stdtyp...and-or-not
Things that are logic False:
Empty lists []
Empty tuples (,)
Empty dictionaries {}
Empty strings ""
Empty ranges range(0)
The number zero (0, 0.0, 0j)
None
False
"P" is a non-empty string, so it is True as far as our "or" statement. So if Player = "R", the "or" will return True (x is True), othewise the "or" will return "P". You may as well delete the or "S" or "Q" parts because they will never be evaluated.
def study_or(Player): print(f'{Player} == "R" is {Player == "R"}') print(f'{Player} == "R" or "P" is {Player == "R" or "P"}') print(f'{Player} == "R" or "P" or "S" is {Player == "R" or "P" or "S"}') print(f'{Player} == "R" or "P" or "S" or "Q" is {Player == "R" or "P" or "S" or "Q"}')I run this code with Player = "R" and it prints this:
Output:R == "R" is True
R == "R" or "P" is True
R == "R" or "P" or "S" is True
R == "R" or "P" or "S" or "Q" is True
This is probably exactly what you expect to happen, so it is of little interest (for now)Lets try Player = "P"
Output:P == "R" is False
P == "R" or "P" is P
P == "R" or "P" or "S" is P
P == "R" or "P" or "S" or "Q" is P
As expected, Player == "R" is False, but you didn't expect Player == "R" or "P" to be "P" did you?From the documents : https://docs.python.org/3/library/stdtyp...and-or-not
Quote:x or y: f x is false, then y, else xIn your example, x is Player == "R" and y is "P". Player == "R" is False, so the "or" looks at "P". Is "P" True, or is it False? In Python most things are treated as "True" when used in a logic operation. The number of things treated as False is a much shorter list.
Things that are logic False:
Empty lists []
Empty tuples (,)
Empty dictionaries {}
Empty strings ""
Empty ranges range(0)
The number zero (0, 0.0, 0j)
None
False
"P" is a non-empty string, so it is True as far as our "or" statement. So if Player = "R", the "or" will return True (x is True), othewise the "or" will return "P". You may as well delete the or "S" or "Q" parts because they will never be evaluated.