当前位置:   article > 正文

python未定义名称_Python代码,未定义名称

可以未定义名称

你的问题是缩进。在

在函数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')

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/904095
推荐阅读
相关标签
  

闽ICP备14008679号