Search code examples
pythonconditional-statementsoperators

How do I use both the OR condition and the '<=' and '>=' functions in a single line


Beginner here. I've posted all code but I believe the error is contained to the two specific lines of code at the bottom in bold. Clearly my syntax is wrong but I can't understand how; I've tried re-specifying INT for numbers and/or putting each side of the OR condition in parentheses, but nothing works. The error marker/pointer on my screen seems to be placed under the greater than/less than symbols. It also throws an error even if I simplify to remove the OR condition.

final_score = str(digit_one) + str(digit_two)
print(f"So the two digit score is {(int(final_score))}")

# 3of3 Final Outputs
**if final_score (<= 10) or (>= 90):**

    print(f"Your score is {final_score}, you go together like coke and mentos.")

**if final_score >= 40 and <= 50:**

    print(f"Your score is {final_score}, you are alright together.")

else:

    print(f"Your score is {final_score}.")

Solution

  • You just have to repeat the variable before each condition. Besides, python syntax does not requires parentheses. Try this:

    if final_score <= 10 or final_score >= 90:
      print(f"Your score is {final_score}, you go together like coke and mentos.")
    if final_score >= 40 and final_score <= 50:
      print(f"Your score is {final_score}, you are alright together.")
    else:
      print(f"Your score is {final_score}.")