Codecademy学生成为老师

时间:2014-04-22 11:45:53

标签: python

我对Codecademy的课程有疑问。有人可以帮帮我吗?

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 = 0
    total = sum(numbers)
    result = float(total) / len(numbers)
    return result

def get_average(student):
    homework = 0.1 * average(student["homework"])
    quizzes = 0.3 * average(student["quizzes"])
    tests = 0.6 * average(student["tests"])
    return homework + quizzes + tests

student = [lloyd, alice, tyler]

students = [lloyd, alice, tyler]

def get_class_average(students):
    results = []
    for each in students:
        results.append(get_average(student))
    return average(results)

“糟糕,再试一次。你的get_class_average函数是否只接受一个输入(学生列表)?你的代码抛出了”列表索引必须是整数,而不是str“错误。”

1 个答案:

答案 0 :(得分:1)

student是一份全球名单。目前还不清楚你为什么试图将它传递给你的for循环中的get_average()(或者为什么它存在)。你可能意味着get_average(each)