9. How is everybody doing? Code error!


I do not know why the code is not working. Until the last two Print commands, it was working fine, but when I added the "prints" it started giving me error messages. I compared this code to what others have posted and it looks similar. Any suggestions?

The error messages are:
Traceback (most recent call last):
File "python", line 50, in
File "python", line 48, in get_class_average
File "python", line 26, in get_average
TypeError: list indices must be integers, not str

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) / len(numbers)
    return total
def get_average(student):
    homework = average(student["homework"]) 
    quizzes = average(student["quizzes"]) 
    tests = average(student["tests"]) 
    return homework *0.10 + quizzes*0.30 + tests*0.60
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"
        return "F"
print get_letter_grade(get_average(lloyd))

students = ["lloyd", "alice", "tyler"]
def get_class_average(students):
    results = []
    for student in students:
    return average(results)
print get_class_average(students)
print get_letter_grade(get_class_average(students))


you shouldn't have quotes around homework, quizzes, and tests.


Hi! I took out the quotation marks, but it did not help.
When I ran than part of the code before (with the quotes) it was working.

Any other ideas?


also take the quotes out here :slight_smile:

do you know why?
instead of being strings, they need to be a dictionary that holds information.
if you have any questions, let me know!


Yes! That worked! Thank you!!!
I do have another question for you, though not about the assignment (assuming you have already completed this module): Do you have suggestions for where to go next after the Codecademy program? Books or courses?


Well I assume that python is going to take you a while to complete, because it's long, but even if you are done soon, I suggest going doing some other CodeCademy languages. If that's not really your thing, there is a really good MIT Open Course Ware class, (here is the link to the introductory lesson, but you can skip that one and do the next lesson if you'd like there's also a next button that you can flip through lessons) that has problem sets as well as my favorite thing - video lectures! They're very good at explaining the concepts behind why certain computer science things are the way they are. It's all in python, and although the first 3 or 4 lessons may be easy because you know python, there are so many good things to learn about python and using it in real life on your own computer. I hope this helps! I also suggest www.stackoverflow.com for any [beta] documentation or questions you may have


Thank you! I have a relatively free week so hope to have lots of time for Python in the next few days.


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