Oops, try again. get_average(alice) returned 79.9 instead of the expected 91.15

#1

import math
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))
a= total/len(numbers)
return a
def get_average(students):
students = [lloyd,alice, tyler]
for student in students:
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
homework_weight = homework * 0.1
quizzes_weight = quizzes *0.3
tests_weight = tests * 0.6

``return homework_weight + quizzes_weight + tests_weight``

#2

alright,actually it didn't ask you to use the for loop or to create a students list so you will have to delete that part all what you 'll do is to multiply the 3 averages by their weights i'll give you an example and you will continue
return (homework*.1)+(quizzes*................you continue.......
i wish this will help and keep your post updated

#3

``````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 *= 0.10
quizzes *= 0.30
tests *= 0.60
return homework + quizzes + 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 = []
for student in students:
results.append(get_average(student))
return average(results)

students = ["lloyd","alice","tyler"]

print get_class_average(students)

Error

``````Traceback (most recent call last):
File "python", line 56, in <module>
File "python", line 51, in get_class_average
File "python", line 27, in get_average
TypeError: string indices must be integers, not str``````

Not sure what's up at this point. It was a little buggy and not copying my code correctly the last few lessons. Just want to see if I'm missing a function or anything else that may have left. Might be a white space issue. I'll check that after I post.

Thanks for any help

**I figured out my mistake it was caused by trying to write code that was lost from a previous message

#4

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