Home > Blockchain >  How to properly structure "for scores less than 10 or greater than 90" within an if statem
How to properly structure "for scores less than 10 or greater than 90" within an if statem

Time:10-19

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:
    ...
  • Related