除了TypeError之外的语法无效?

时间:2018-04-15 02:00:01

标签: python python-2.7 try-except

除了TypeError之外,为什么我会得到一个无效的语法?如何修复它?

Try:
score=float(raw_input("What is your score?"))
If score>100 or score<0:
print "please enter a score between 100 and 0"
except TypeError:
print "Please enter your score in digits"

1 个答案:

答案 0 :(得分:2)

    score = float(input("What is your score?\n"))
    try:
        if score > 100 or score < 0:
            print("please enter a score between 100 and 0")
        elif score >= 80:
            print("GPA is 8.0 and Grade is A+")
        elif score >= 70:
            print("GPA is 7.0 and Grade is A")
        elif score >= 65:
            print("GPA is 6.5 and Grade is B")
        elif score >= 60:
            print("GPA is 6.0 and Grade is C")
        elif score >= 55:
            print("GPA is 5.5 and Grade is D")
        elif score >= 50:
            print("GPA is 5.0 and Grade is E")
        else:
            print("GPA is 0 and Grade is O")
    except TypeError:
        print("Please enter your score in digits")

除了应该完全在&#39;尝试&#39;。您没有在try下添加,因此语法无效