# Part of a Whole - Returning 83.6 instead of 91.5 as expected

#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)
x = total/len(numbers)
return x

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"

def get_class_average(students):
results=[]
results.append(get_average(lloyd))
results.append(get_average(alice))
results.append(get_average(tyler))
return average(results)

#2

you get_class_average function should be able to calculate the class average for a class of any size (one, two or three students)

#3

I tried this:
results.append(get_average(lloyd,alice,tyler))

but the error said only use 1 argument instead of three

#4

that still will only work for a class for 3 students, it should work in all cases:

``````def get_class_average(students):
print students

get_class_average(alice)
get_class_average(alice, lloyd)
get_class_average(alice, lloyd, tyler)``````

your function should work all this cases, with varying class size

#5

You may possibly create a variable which takes all of the student names and places them in a variable which you could then use as the one argument.

#6

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