# Part of the Whole What's wrong with my code

#1

I don't under stand what is with this code:
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)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
homework = homework * 0.1
quizzes = quizzes * 0.3
tests = tests * 0.6
weighted_grade = homework + quizzes + tests

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

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

The error comes as get_class_average([alice]) resulted in an error: list indices must be integers, not string. Can somebody please tell me what is wrong

Thanks!

#2

@mr.stoleyourhorse: If I'm not wrong, you were supposed to iterate over the list you'll pass an argument to the function get_class_average so you should've used a loop to iterate over it and each time, call the get_average() function to pass each student, to later append to the list and to later return the average of that new generated list.

If my answer wasn't clear, let me know and I'll find another way to explain!

#3

Can you please try this piece of code...

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