我正在尝试创建一个简单的测试记分器,对测试进行评分并为您提供响应 - 但是一个简单的if / else函数未运行 -
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!"
错误是 -
Traceback (most recent call last):
File "python", line 6
elif testScore >= 60 and <= 71:
^
SyntaxError: invalid syntax
答案 0 :(得分:6)
您在elif声明中错过了testScore
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!"
答案 1 :(得分:2)
下面显示的方法是更好的解决方法,在比较/检查数字时,总是需要将类型转换为整数。
python中的input()通常采用字符串
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!")