For The Record - where the student becomes the teacher


#1


"Oops, try again. Did you print out each student's name? It looks like "Lloyd" wasn't printed."

I'm not sure what im doing wrong

Replace this line with your 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 lloyd
print alice
print tyler

edit: i tried a different way and it worked. However, it took too long isnt there a simpler/quicker way of doing it?

print lloyd ["name"]
print lloyd ["homework"]
print lloyd ["quizzes"]
print lloyd ["tests"]

print alice ["name"]
print alice ["homework"]
print alice ["quizzes"]
print alice ["tests"]

print tyler ["name"]
print tyler ["homework"]
print tyler ["quizzes"]
print tyler ["tests"]


#2

Hi @navinamahesh ,

Use a for loop to iterate through the global students list that you created. Here is a header for the loop ...

for student in students:

Then, inside the loop, the student variable will represent the dictionary for each student, in turn. Therefore, you can use that variable with the key that maps to each value, in a manner similar to what you already have.

For example, you can replace this ...

print lloyd["name"]

... with this ...

print student["name"]

#3

i used a loop but it still gives me a string error. PLease help


#4

@megawhiz26318 ,

We cannot help without our knowing what is inside your loop. Please post your code for us.


#5

is there a way to go from this

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

to something like this.

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

I feel like you should be able to condense eveything to one line. but not sure how


#6

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