# Exercise explanation

#1

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

can anyone explain the procedure that python follows when the code above is run?

I expected the output (which is actually wrong) to start as following :
“Lloyd”
“Alice”
“Tyler”

print student[“name”] is the first line in the sequence so python should first go through all dictionaries and print value of key “name”.

Why is it actually different?

#2

As I understand and I might be wrong (as I just started), since you made a loop
for student in students:
print student[“name”]
print student[“homework”]
print student[“quizzes”]
print student[“tests”]
so it will first take the first student in your students’ list and then will print the name, homework, quizzes and tests so will finish with one cycle then takes the second same prints name, homework, quizzes and tests etc depends how big the students’ list. If you want it to print your expected output then you will need to create something like this:

#3

This is correct yes.