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
asked Nov 2, 2017 at 12:10
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!"
answered Nov 2, 2017 at 12:24
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!")
answered Nov 4, 2017 at 4:17

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!")
answered Sep 8, 2021 at 12:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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