9. How is everybody doing?



The instructions of this exercise are:

  1. Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].

  2. Then, print the result of get_letter_grade for the class's average.

The error messages are these:

Traceback (most recent call last):
File "python", line 56, in
File "python", line 53, in get_class_average
File "python", line 28, in get_average
TypeError: string indices must be integers, not str

I didn't convert the variables to string, and even if I put a str(variable), it shows as an invalid syntax. Please anybody can help me to fix this?

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)
    result = total / len(numbers)
    return result
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    homework = 0.1*homework #retirar parenteses
    quizzes = 0.3*quizzes
    tests = 0.6*tests
    media = sum([homework, quizzes, tests])
    return media
def get_letter_grade(score):
    #score = get_average(student)
    if score >= 90.0:
        return "A"
    elif score >= 80.0:
        return "B"
    elif score >= 70.0:
        return "C"
    elif score >= 60.0:
        return "D"
        return "F"

def get_class_average(students):
    results = []
    for student in students:
        get = get_average(student)
    return average(results)
print get_class_average(lloyd)
print get_class_average(alice)
print get_class_average(tyler)
print get_letter_grade(get_average())Replace this line with your code.


where is your students list from 3. put it together?

then you can call get_class_average() with students list as arguments

this will give you the average grade for the class, then you can use get_letter_grade to convert this class average grade, into a letter class average grade


I'm sorry, I didn't understand "where is your students list from 3. put it together?"

could you write an example of what you are explaining?

Thank you


put it together is one of the exercises you completed in this track (link), in this you build a list. You are going to need this list. You can use it as argument for get_class_average


Great! It works now.

You are the best!

Thank you!!!