Reputation:
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
Upvotes: 1
Views: 11730
Reputation: 64
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!")
Upvotes: 0
Reputation: 2414
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!")
Upvotes: 3
Reputation: 1943
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!"
Upvotes: 6