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 Answers 3
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!"
Comments
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
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!")
elif testScore >=60 and <=71:should be modified into thiselif 60 <= testScore <= 71: