赞
踩
你的问题是缩进。在
在函数lett_grade(student name)中,该函数中的所有内容都是""" Gets the students letter grade A-F"""。在
因此,if语句是函数的out,因此studentname是未定义的。在
以下是您编辑的代码:lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
def average(numbers):
total = sum(numbers)
total = total/len(numbers)
return total
def student_avg(student):
"""Returns weighted average"""
homework = average(student['homework']) * 10/100
quizzes = average(student['quizzes']) * 30/100
tests = average(student['tests']) * 60/100
return homework + quizzes + tests
def lett_grade(studentname):
""" Gets the students letter grade A-F"""
if student_avg(studentname) >= 90:
print('A')
elif 90 > student_avg(studentname) >= 80:
print('B')
elif 80 > student_avg(studentname) >= 70:
print('C')
elif 70 > student_avg(studentname) >= 60:
print('D')
else:
print('F')
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。