# Please can someone help with "Just Weight and See"

#1

I have typed this in and it is not working. Please can someone help.

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"])

It says Oops, try again. get_average(alice) returned 9.75 instead of the expected 91.15

#2

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"])

here

#3

Thank you!!!!!!

#4

I don't really understand why if you're defining

``````homework = average(student["homework"])
quizzes = average(student["quizzes"]
tests = average(student["tests"])``````

that you have to retype all of that after return to multiply by their weights?

Shouldn't you be able to type it as

`return 0.1 * homework + \ 0.3 * quizzes + \0.6 * tests`

? Otherwise, why did you bother setting those values equal to those variables in the first place?

I ended up typing it like you did above as I've formatted below, I'd just like to understand why it doesn't work the way I've written above:

``````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"])``````

EDIT:
I messed with it some more and realized that in order for it to pull from those values I need a for loop. This code also worked for me:

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

#6

Could you explain why you need a for loop? I don't understand that part.
Thanks!

#7

You don't need a for loop. I only used one because I didn't see any reason to have defined the variables if I'm not going to use them. In this code below there's no reason to have defined each of the three variables (homework, quizzes, and tests) if you're just going to call the average() function for each of them again but also multiply by their percentage value:

``````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"])``````

Basically the code above does the same thing as this code would:

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

If I want to actually use the variables I set up as homework, quizzes, and tests, I have to use a for loop to be able to use the variables for each student.

At least I think. I'm still very much a beginner, too so this is just my best understanding of why the code works that way.