1

I am trying to create a simple test-scorer that grades your test and gives you a response - but a simple if/else function isn't running -

Python -

testScore = input("Please enter your test score")


if testScore <= 50:
  print "You didn't pass... sorry!" 
elif testScore >=60 and <=71:
  print "You passed, but you can do better!"

The Error is -

Traceback (most recent call last):
  File "python", line 6
    elif testScore >= 60 and <= 71:
                              ^
SyntaxError: invalid syntax
3
  • 1
    What is the error? Commented Nov 2, 2017 at 12:11
  • 5
    Python is high-level but not straight-up English.. elif testScore >=60 and <=71: should be modified into this elif 60 <= testScore <= 71: Commented Nov 2, 2017 at 12:13
  • It works now. Thanks! Commented Nov 2, 2017 at 12:15

3 Answers 3

6

You missed testScore in elif statement

 testScore = input("Please enter your test score")


if testScore <= 50:
  print "You didn't pass... sorry!" 
elif testScore >=60 and testScore<=71:
  print "You passed, but you can do better!"
Sign up to request clarification or add additional context in comments.

Comments

3

The below shown way would be the better way of solving it, you always need to make the type conversion to integer when you are comparing/checking with numbers.

input() in python would generally take as string

 testScore = input("Please enter your test score")
 if int(testScore) <= 50:
     print("You didn't pass... sorry!" )
 elif int(testScore) >=60 and int(testScore)<=71:
     print("You passed, but you can do better!")

Comments

0

You made some mistakes here:

  • You are comparing a string with an Integer if testScore <= 50:

  • You have missed the variable here --> elif testScore >=60 and <=71:

I think those should be like this --->

  • if int(testScore) <= 50:
  • elif testScore >=60 and testScore<=71:

And try this, it is working --->

testScore = input("Please enter your test score")
if int(testScore) <= 50:
    print ("You didn't pass... sorry!") 
elif testScore >=60 and testScore<=71:
    print ("You passed, but you can do better!")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.