# 8.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=float(sum(numbers))

def get_average(student):
homework=float(sum(student["homework"]))/len(student["homework"])
quizzes=float(sum(student["quizzes"]))/len(student["quizzes"])
tests=float(sum(student["tests"]))/len(student["tests"])
return (homework*10+quizzes*30+tests*60)/100

if score>=90:
return "A"
elif score>=80 and score<90:
return "B"
elif score>=70 and score<80:
return "C"
elif score>=60 and score<70:
return "D"
else:
return "F"

def get_class_average(students):
results=[]
for student in students:
return get_average(student)
results.append(get_average(student))
return average(results)

Hi..can you please tell me what is wrong with this code?The error message is showing get_class_average([alice,lloyd)]returned 91.15 instead of 85.85...Thank You

#2

Hi you should indent this line

``return average(results)``

like that

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

#3

It is still showing the same error...

#4

then remove the first return

`` return get_average(student)``

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

#5

Ya...It worked..!!Though what was the problem?..Thank you

#6

it was on this line

`` return get_average(student)``

because the lesson aske you to call the function get_average() and not to return it.

#7

Try this format

def get_class_average(students):
----results = []
----for student in students:
--------results.append(get_average(student))
----return average(results)

#8

Wizy thanks for the quick fix...