4. For the Record


#1

For the Record

My 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 student['name']
    print(' '.join(map(str, student['homework'])))
    print(' '.join(map(str, student['quizzes'])))
    print(' '.join(map(str, student['tests'])))

Output:

Lloyd
90.0 97.0 75.0 92.0
88.0 40.0 94.0
75.0 90.0
Alice
100.0 92.0 98.0 100.0
82.0 83.0 91.0
89.0 97.0
Tyler
0.0 87.0 75.0 22.0
0.0 75.0 78.0
100.0 100.0
None

Error:

Did you print out each student's homework scores? It looks like Lloyd's homework scores weren't printed correctly.

So... Why it's not correct output? It's looks ugly with brackets. xD
Why it's need to be printed like arrays?


#2

Hi @netscum ,

Yeah, the output does look better without brackets. Consider the Codecademy exercises to be a form a practice. The submission correctness test (SCT) for an exercise often expects a specific format, and will not pass submissions that implement improvements. What I often do is to copy my code into a local file on my own computer where I can experiment with it without getting an "Oops" message in response.


#3

Even before you do the ' '.join(map(str, ....
you can just write it simply, no complications as follows:

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 data in students:
    print data['name']
    print data['homework']
    print data['quizzes']
    print data['tests']

#4

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 name in students:
print name
for homework in students:
print homework
for quizzes in students:
print quizzes
for tests in students:
print tests

Error:
Did you print out each student's homework scores? It looks like Lloyd's homework scores weren't printed correctly.

How do i lose this error?
Help needed.Thank you


#5

My print codes are below and other codes are the same:
students = [lloyd,alice,tyler]

for data in students:
print students[students.index(data)]

but I don't know why the output don't print from 'name'>'homework'>'quizzes'>'tests'
it's like this,ex lloyd:

{'quizzes': [88.0, 40.0, 94.0], 'tests': [75.0, 90.0], 'name': 'Lloyd', 'homework': [90.0, 97.0, 75.0, 92.0]}


#6

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