Suggestions welcome. It's doing what it's saying it's not


#1

Apparently it didn't print out Lloyds name (although it has)!! The 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]
for student in students:
    print "Name: " + student['name']
    print "Homework: " + str(student['homework'])
    print "Quizzes: " + str(student['quizzes'])
    print "Tests: " + str(student['tests'])

The output:

Name: Lloyd
Homework: [90.0, 97.0, 75.0, 92.0]
Quizzes: [88.0, 40.0, 94.0]
Tests: [75.0, 90.0]
Name: Alice
Homework: [100.0, 92.0, 98.0, 100.0]
Quizzes: [82.0, 83.0, 91.0]
Tests: [89.0, 97.0]
Name: Tyler
Homework: [0.0, 87.0, 75.0, 22.0]
Quizzes: [0.0, 75.0, 78.0]
Tests: [100.0, 100.0]
None

The fault/warning:

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

So it has printed the data, but for some reason it's not being picked up by the system. Is the code wrong?


#2

@dan_h83,
Try it with (as is asked...)

students = [lloyd, alice, tyler]
for student in students:
    print student['name']
    print student['homework']
    print student['quizzes']
    print student['tests']

#3

Hi @dan_h83 ,

Yes, you did print the name, "Lloyd". But Codecademy does not like that you preceded it with the label, "Name: ". Just do this, instead ...

print student['name']

Also remove the labels from the other data.


#4

Thanks guy's I have noticed that if you add any flavour then they don't like it.


#5

Hi @dan_h83 ,

For some exercises, you can pass, even if you add extra features to your code. It depends upon the particulars of the test that Codecademy performs for that exercise. But, it's a good idea to first follow the instructions precisely, because in an actual production environment, programmers are expected to do that. When you have a group of people working on a project, one renegade programmer can mess things up for everyone, by doing something that the other programmers are not expecting.