我正在尝试完成班级“成绩确定”的作业
编写一个程序,输入 3 个测试分数。程序应确定并显示它们的平均值。然后程序应根据平均值显示适当的字母等级。字母等级应使用标准 10 分制确定:(A = 90-100;B = 80-89.999;C = 70-79.999 等)
到目前为止,我已经能够放在一起,(它的工作平均)
def main():
score1 = input("What is the first test score? ")
score2 = input("What is the second test score? ")
score3 = input("What is the third test score? ")
scoreaverage = score1 + score2 + score3
score = (scoreaverage / 3)
if score < 60:
grade="F"
elif score < 70:
grade="C"
elif score < 80:
grade="B"
elif score < 90:
grade="A"
else:
print score, " is the student's grade average!"
main()
如果我用成绩替换分数,我会得到一个错误。
raceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 16, in main
UnboundLocalError: local variable 'grade' referenced before assignment
所以我的问题是如何让字母等级正确打印?