9/9 "How is Everybody Doing?" - Averages and String Indices Errors


#1
Traceback (most recent call last):
  File "python", line 57, in <module>
  File "python", line 53, in get_class_average
  File "python", line 28, in get_average
TypeError: string indices must be integers, not str

My code looks like this (starting at line 27):

def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    return (0.10 * homework) + (0.30 * quizzes) + (0.60 * tests)

def get_letter_grade(score):
    grades = ["A", "B", "C", "D", "F"]
    if score >= 90 :
        return grades[0]
    elif score >= 80 :
        return grades[1]
    elif score >= 70 :
        return grades[2]
    elif score >= 60 :
        return grades[3]
    elif score <= 60 :
        return grades[4]

print get_letter_grade(get_average(lloyd))

students = ["Lloyd", "Alice", "Tyler"]

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

print get_class_average(students)
print get_letter_grade(get_class_average(students))

Thank you!


#2

To answer my own question, I changed how the list was formatted from

students = ["Lloyd", "Alice", "Tyler"]

to

students = [lloyd, alice, tyler]

This made the interpreter rethink it's position :wink: