# Just weight and see

#1

6/9 Just weight and see

I'm getting 80.55 instead of 91.15 can anybody tell me 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]
def average(numbers):
total = sum(numbers)
total = float(total)
total = total / len(numbers)
def get_average(student):
for student in students:
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return (homework *.1) + (quizzes *.3) + (tests *.6)
print get_average(alice)``````

#2

no need for a loop in the `get_average` function, the get_average should only get the average for one student, you can determine this student by passing as argument in the function call

just remove the loop, you can just use the function parameter

#3

oh thanks it fixed it

#4

do you also understand why this works?

#5

Yea i just realised student already tells it to do it for every student,

#6

sort of yes, you can pass every student you wish as argument when calling the function. This is important to understand, in particular for exercises to come

#7

can you explain it to me?

#8

Well, explaining everything is a bit tricky.

Make a new topic with code + what you don't understand so we can fill in the blanks

#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.