Students Becomes the Teachers 4/9


#1

I must be doing something wrong, the output is correct but I keep getting the error:Oops, try again. Did you print out each student's name? It looks like "Lloyd" wasn't printed; and Lloys is being printed.

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's name: %s" % student["name"]
print 'Homework: %s' % student['homework']
print 'Quizzes: %s' % student['quizzes']
print 'Tests: %s' % student['tests']


#2

Only thing that might help is double quotations "
Otherwise, that was basically my exact code which worked for me.

Here was my code:
students = [lloyd, alice, tyler]
for students in students:
print "Student's name: %s" % students["name"]
print "Student's homework: %s" % students["homework"]
print "Student's quizzes: %s" % students["quizzes"]
print "Student's tests: %s" % students["tests"]


#4

I tried your code, which has extra work thats not needed, and i think that you are doing more than needed so the exersize gets confused. try and do what it tells u in the instructions instead of adding more stuff. sometimes adding more stuff to make it more readable messes up the exersize

students = [lloyd, alice, tyler]

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

#5

I did :

List item

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


console print : line 21, in
TypeError: string indices must be integers, not str.

why?


#6

Make sure your spacing is correct


#7

Thank you guys, I think I put too much, I simplified the answer and just did the minimum require and it pass the check. Thanks.


#8

I am getting the same error! can somebody help us with the answer


#9

change this
students = ['lloyd', 'alice', 'tyler']

for this
students = [lloyd, alice, tyler]

there is a error in the example


#10

much appreciated. it works, mate.


#11

the best way to do it is to understand how the for function works.
try to read it like this,

for x in students
this means for every item in the list students I'm choosing to call this item x for now. now you are telling the code what to do with each item (x) in the students list.

print x['name']
now the code will replace x with an item in students each time it runs. so it will go with lloyd and alice and then tyler.
your final code should be

lloyd = {
"name": "Lloyd",
"homework": [],
"quizzes": [],
"tests": []
}
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]
}
lloyd["homework"]=[90.0, 97.0, 75.0, 92.0]
lloyd["quizzes"]=[88.0, 40.0, 94.0]
lloyd["tests"]=[75.0, 90.0]
students=[lloyd,alice,tyler]

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


#12

`for i in range(len(students)):
print students[i]['name']
for key in students[i]:
print "%s: %s" % (key, students[i][key])

`
That's the code I used. For some reason it keeps telling me llyod's homework scores weren't printed correctly. It appears to have printed correctly yet, it keeps telling me otherwise. what am I missing here?