For the Record


for each student in your students list, print out that student's data, as follows:

print the student's name
print the student's homework
print the student's quizzes
print the student's tests

this gives the correct answer but i feel like im not being efficient at all was there a better answer lol

i expected to be able to print out "name" "quiz" etc...key for each dictionary output instead i ended up using this print sequence which felt amateur. sorry im just trying to understand the logic here . is there any good cheat sheet for python syntax. i keep having to reference youtube videos and google searches...but the way people tend to short cut is advanced for us code academy beginners.

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 lloyd["name"]
    print alice["name"]
    print tyler["name"]
    print lloyd["homework"]
    print alice["homework"]
    print tyler["homework"]
    print lloyd["quizzes"]
    print alice["quizzes"]
    print tyler["quizzes"]
    print lloyd["tests"]
    print alice["tests"]
    print tyler["tests"]


You iterate through the students list, which is good, but then you don't use that to your advantage (The way you have done it, you might as well just get rid of the for loop). You need to use student in your print statements. For example:

for student in students:
    print student["name"]

Think of student like a variable; For each iteration of the for loop, student equals a different value from the students list.


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