I'm simply trying the following:
if score < 10 or > 90:
print(f"Your score is {score}, you go together x and y.")
but it gives an error:
if score < 10 or > 90:
^
SyntaxError: invalid syntax
Would someone explain the reason behind it not liking > 90? Its type is integer. Instead of just looking at the solution I want to understand why.
CodePudding user response:
>
and or
are binary operators. You mustn't confuse coding with natural language, think more in the ways of statement or predicate logic. The correct syntax here would be:
if score < 10 or score > 90:
# ...
You can, however, use comparison operator chaining to get the same condition (possibly more readable):
if not (10 <= score <= 90):
# ...
CodePudding user response:
if score < 10 or score > 90:
...