Student become the


#1

Hello,

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!


#2

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.


#3

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


#4

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


#5

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


#6

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


#7

my loop was for student in students:


#8

So then this should work...


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

#9

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


#10

it works!!! man,you are cool


#11

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

#12

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