For the Record


#1


https://www.codecademy.com/courses/python-beginner-en-qzsCL/0/4?curriculum_id=4f89dab3d788890003000096


Traceback (most recent call last):
File "python", line 23, in
TypeError: list indices must be integers, not str
Oops, try again. Your code looks a bit off--it threw a "list indices must be integers, not str" error. Feel free to peek back at earlier exercises if you need a syntax refresher!


It's supposed to cycle through the name, homework, quizzes, and tests of each student.


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]
}

students = [lloyd, alice, tyler]

for name in students:
    print students[name["name"]]
    print students[name["homework"]]
    print students[name["quizzes"]]
    print students[name["tests"]]


#2

A for loop should help us to limit repetition of patterns. The above is over-complicated and needs a re-think.

for student in students:

student is a dictionary, not a name. You'll want to avoid confusing things with incorrect variable names (those that do not describe their object). A name is a string, not a dictionary. Just something to keep in mind.

    print student['name']
    print student['homework']
    print student['quizzes']
    print student['tests']

#3

It worked. Thanks, I didn't think it'd make the connection on it's own.


#4

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