# Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected

#1
``````indent preformatted text by 4 spaces
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]
# Add your function below!
def average(numbers):
average = 0
total = sum(numbers)
total = float(total)
divide = total/len(numbers)
average = 0 + divide
return average
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return .1 * homework +  .3 * quizzes +  .6 * tests
def get_letter_grade(score):
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(classroom):
results = []
for yam in students:
results.append(get_average(yam))
return average(results)``````

#2

Assuming your `get_class_average` function is indented correctly, it is as follows ...

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

The problem is that here ...

``for yam in students:``

... your function ignores its parameter, `classroom`, and accesses the global list, `students` instead. To access the parameter, do this ...

``for yam in classroom:``

... or change the name of the parameter to `students`.

#3

Ok, after a lot of trial and error, this worked:

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]
}

# Add your function below!

def average(numbers):
total = sum(numbers)
total = float(total)
return total / len(numbers)
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
sum = homework * .1 + quizzes * .3 + tests * .6
return sum
def get_letter_grade(score):
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"
get_letter_grade(get_average(lloyd))

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