Student become the



I need help for the student become teacher section. And I am having a hard time with this activities. 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

First I tried this code:
for student in students:
print student["name"]
print student["homework"]
print student["quizzes"]
print student["tests"]

It didn't work.

Then the second code was:

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

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

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

That didn't work either. So I need some help!


First off, do you have a students list defined?

students = [lloyd, alice, tyler]

As for your latter example, which is not the solution, btw, the dictionary names need to match the defined ones, without 's. Not important, since the for loop is the way to do this.


yeah I have students = [lloyd, alice, tyler]


Then your for loop should work. Be sure the list is written above the for loop.


I still don't understand so the student = [lloyd, alice, tyler] comes after


That's the right place for it. What does your for loop look like?


my loop was for student in students:


So then this should work...

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


you can try liake this
print students[0]['name']
print students[0]['homework']


it works!!! man,you are cool


If we wish to reduce repetition in our code, we can cycle through the keys...

for student in students:
    for key in student:
        print student[key]

If the subject of string formatting has come upi already, this will look familiar...

for student in students:
    for key in student:
        print "%s: %f" % (key, student[key])


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