How's Everybody Doing? Correct answer but still has error message


#1

I got a correct answer but this error message keeps popping up:

Oops, try again. One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade

What's wrong with my code?

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]
}
students = [lloyd,alice,tyler]
# Add your function below!
def average(numbers):
    return sum(numbers) / float(len(numbers))
def get_average(student):
    homework = average(student["homework"]) 
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return 0.1 * average(student["homework"]) + 0.3 * average(student["quizzes"]) + 0.6 * average(student["tests"])
def get_class_average(students):
    results = []
    for student in students :
        results.append(get_average(student))
    return average(results)
def get_lettter_grade(score):
    if score >= 90:
        return "A"
    elif score >= 80:
        return "B"
    elif score >= 70:
        return "C"
    elif score >= 60:
        return "D"
    else:
        return "F"

print get_class_average(students)
print get_lettter_grade(get_class_average(students))

#2

In average(),

return float(sum(numbers)) / len(numbers)

is more true to the point.

The sum of a list of random numbers may a lot more easily be construed as a float than can be coerced a counting number into one.

In get_average() your return statement repeats the three lines above it. Try using just the variables in the return statement.

Not sure either of these points to the actual error, but it will clean up the code.


#3

I changed the average() but the same error code still shows up.


#4

As one might have still expected since what you changed was not an error, just a semantics issue. Have you also revised the get_average() function?


#5

This is the only thing that stands out. The space before :.

Even though the get_average function is bloated with code it does not use, it will still return the correct value. So it has to be something else.


#6

def average(numbers):
    return float(sum(numbers)) / len(numbers)
    
def get_average(student):
    cat = {'homework': 0.1, 'quizzes': 0.3, 'tests': 0.6}
    aggr = [(average(student[k]), k) for k in student if k != 'name'] 
    return round(sum([k[0] * cat[k[1]] for k in aggr]), 2)

Every tester knows that there are alternative appoaches. This is another one.


#8