# Help with student becomes the teacher(part of the whole)

#1

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

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return(0.1 * homework + 0.3 * quizzes + 0.6 * tests)
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"

students = [lloyd, alice, tyler]
def get_class_average(students):
results = []
for student in students:
results.append(get_class_average(student))
return average(results)``````

#2

We're passing dictionary (tyler,alice,lloyd are dictionaries) so this function won't able to handle it,its not even defined yet.
To deal dictionary and find average we use `get_average()` function

#3

@greentreemee is right, to calculate the class average we first need to calculate the average grade of each student use `get_average()`, which we append to results list.

#4

could you please write down the code for that part? because I'm confused and I've been trying to sort it out for a long time.
this is the message I get after I submit it.
Oops, try again. get_class_average([alice]) resulted in an error: maximum recursion depth exceeded

#5

here:

``results.append(get_class_average(student))``

you should append the average grade of the student, to calculate the average grade of student use `get_average()`, you use get_class_average, which causes the function to call itself (recursion), but given there is no base case you will reach a maximum depth (sort of like an infinity loop, but then with functions)

#6

students = [lloyd, alice, tyler]
def get_average(student):
results = []
for student in students:
results.append(get_average(student))
return average(results)

this is what I did but it still doesn't work.

#7

better, but i spotted another mistake, here:

``def get_average(student):``

this should be `students`, as it says in instructions

#8

``````students = [lloyd, alice, tyler]
def get_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)``````

I did that but it still doesn't work. get_class_average([alice]) resulted in an error: maximum recursion depth exceeded. this the message it keeps giving.

#9

weird, your code should work now. Refresh the page, try a different browser. Did i miss something @greentreemee?

#10

well, I refreshed the page and this is the error message I get.
Oops, try again. Make sure you have defined get_class_average
this was what I did earlier.
I tried to define then it went back to the previous error message I got earlier.

#11

here:

``def get_average(students):``

this should be get_class_average, then inside the function you call get average, so you should have:

a get_average function somewhere earlier in your code
a get_class_average
in the get_class_average function, you call get_average

a function call doesn't have to have the same name as the function, you can call a different function from within a function

#12

sorry to disturb you but I'm confused.

``````students = [lloyd, alice, tyler]
def get_class_average(get_average):
get_average(students)
results = []
for student in students:
results.append(get_average(student))
return average(results)``````

should code look like this?
this is the message I get.
Oops, try again. get_class_average([alice]) resulted in an error: 'list' object is not callable

#13

sorry to disturb you but I'm confused.
students = [lloyd, alice, tyler]
def get_class_average(get_average):
get_average(students)
results = []
for student in students:
results.append(get_average(student))
return average(results)
should code look like this?
this is the message I get.
Oops, try again. get_class_average([alice]) resulted in an error: 'list' object is not callable

#14

oh wait. I've got that sorted out. Thank you so much!

#15

here:

``def get_class_average(get_average):``

why did you change your students parameter to get_average?

remove this line:

``get_average(students)``

Do you even understand what you are doing?

Programming is about understanding, being able to solve a problem. Just randomly trying is a really bad approach

#16

yes I do understand what i'm doing. I've got that sorted out already. it works for me perfectly. Thanks!
what I had written earlier was wrong, I just now corrected it and it works.

#17