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

File "main.py", line 34
    if number <10 and >90: 
                      ^
SyntaxError: invalid syntax

I'm very new to learning Python and I can't understand why I'm getting an error here. Any help is appreciated.

Edit: Thanks for the help. Yes, I accidentally typed 'and' instead of 'or' for the first statement. And the problem was I wasn't putting the variable name in front of each >/<.

mc_pulp
  • 17
  • 3

2 Answers2

2

You need to specify the variable being compared for every inequality in the conditionals; Python won't infer that information for you.

So:

if number <10 and >90:

should be

if number <10 and number>90: # This condition will never fire, since a number can't be less than 10 and above 90. You might want to use 'or' rather than 'and' here.

and

elif number >= 40 and <= 50:

should be

elif number >= 40 and number <= 50:
BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
1

I guess you are trying to achieve,

1st condition - where the number is less than 10 or greater than 90.

2nd condition - where the number can be greater than or equal to 40 and less than or equal to 50.

if number < 10 or number > 90: 
    print(f"Your score is {number}, you go together like coke and mentos.")
elif 40 <= number <= 50:
    print(f"Your score is {number}, you are alright together.")
else:
    print(f"Your score is {number}.")
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47