# Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

#1

I'm beginner and apparently need someone's help

Here's my coding
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]
}
"""
h = 97.5
"""
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 = float(total)
return float(total) / len(numbers)

# weighed average function definition

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

# get grade function definition from score

if score >= 90.0:
return "A"
elif score < 90.0 and score >= 80.0:
return "B"
elif score < 80.0 and score >= 70.0:
return "C"
elif score < 70.0 and score >= 60.0:
return "D"
else:
return "F"

# get class average function definition from each students average

results = []
classes = [lloyd, alice, tyler]

def get_class_average(student):
for student in classes:
result = get_average(student)
results.append(result)
return average(results)

get_class_average(classes)

This is my error message
Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

Would you tell me what I missed?

``Replace this line with your code.``

#2

You're likely processing the wrong students. You'll want to add print statements which follow along in what your program does step by step, or even just read your code carefully to find where you're using the wrong students.

Your function takes an argument, that argument is the students that your function should be looking at. If you're referencing any other students then that is incorrect.

You may also find it helpful to do what your function is supposed to do manually and compare that to the error message so that you know that you've understood what is supposed to happen. You can then also compare what you did with what the code says in your function.

#4

I did manage to solve this problem by looking at argument carefully.

#5

I had the same error either. I think this is the error of the program itself.

If we get trace of our program step by step (espetialy at

, we will see that score of alice is 91.3 and
the average of all the results are 83.87.
So we are true, we find the score of alice trully and 83.87 is the the average of scores of the class.
I am sure this is the error of the website program.

#6

Wooow, my program works well!
I dont know what the difference is. But if you the "result=[]" inside the "def get_class..."
that would be work!!!

I dont know the difference and it does not seem to have any difference!

Also change the variable of your def from student to classes.

because when you call your def at the end with classes, the name of student in the def part, will change to the classes! I hope you understand what I mean!