11.4- For the Record problem (please help me I have to do this for school and I don't know what I'm doing)


#1

I got the error message "Oops, try again. Your code looks a bit off--it threw a "name 'student' is not defined" error. Feel free to peek back at earlier exercises if you need a syntax refresher!" and "Traceback (most recent call last):
File "python", line 21, in
NameError: name 'student' is not defined" for this set of code

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]
print student.name
print student.homework
print student.quizzes
print student.tests


#2

where is your for loop?


#3

How do you do that? I'm more than a little bit confused


#4

general syntax:

for item in list:
    print item

will print each item in list

in case you have student in students list


#5

so far I have 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]
}

students = [lloyd,alice,tyler]
for student in students:
    print student[name]
    print student[homework]
    print student[quizzes]
    print student[tests]

where do I go from here?


#6

why are name, homework, quizzes and tests variables?


#7

I wasn't aware you needed a variable for those


#8

how do you make it work the way it should?


#9

you don't, i asked you why decided to use variables? Because it doesn't make much sense. Why not simply use strings as keys to retrieve the values from the dictionary?


#10

oh that could be the problem I'm going to fix that


#11

that fixed it thank you


#12