For the Record


#1



For the Record

name lloyd is not defined


to display the name

students = [lloyd,alice,tyler]

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

for item in students:
    print student[name]


#2

Well first off, you have the first printing necessary but you need the other three printings as well which include homework, quizzes, and tests. Also, you need your item like name in qoutes. So for example:

print student['name']

#3

I had the list, it was just at the top. When I add the other things I get that name is not defined:


#5

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


#6

Yeah sorry about the list. I can be blind sometimes lol. It would seem though you need to put your items like name homework etc in quotes. Also, it is just student. Not students.


#7

First off, remember that students is a list with references to three dictionaries.

for student in students:

will iterate that list. Each student reference is a dictionary, as we noted above; so,

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

But if this is still not covered yet, then I guess the drawn out approach is all we can use, inside the outer loop, using the quoted key names of the temporary student object.


#8

Instructions:
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

I agree @mtf that obviously it is not the most efficient or best way to do this but I assume that at least here it is not time to cover that yet. I think it is still good to realize that there is better ways to do this and that we should strive to learn those once we have built a strong foundation with the basics.


#9

On this I disagree. There is enough of a foundation in place, and what you are suggesting is a step backward, not forward. It does nothing to seek a sensible solution and only validates a weak one. This pupil is not paying attention and is instead attempting to race through the track just for the completion, regardless that nothing is learned. I don't intend to support or encourage that.


#10

I disagree. A.) the instructions call for that so if that is too easy or weak then maybe it should be changed. I hope changes like that will be made in the new Learn Python when it comes out. B.) That is very quick to judge the intentions of the person without ever even inquiring of the person. I don't claim to know either but I don't see how it is even possible to judge in this case with no evidence at all especially not knowing where this person is in their "coding journey" C.) I don't want to support or encourage weak learning either. However, even in great language courses like this one, some lessons need to be changed for better learning and maybe this is one of them. At this point should a python user be able to do what is suggested above? probably. However, that is not what is in place now and thus even if it more "sensible" it is not what is taught. This where one can learn the lesson as now but also seek to learn better ways to do what they just learned.


#11

Without seeing the lesson we are both still guessing. Clearly we are equipped with the knowledge of how to iterate over both lists and dictionaries by this stage. If one chooses to take the instructions literally, without regard for the hint in the question, then so be it. And yeah, it does take hubris to make assumptions the way I did, but I make no apology. The OP should well know by now that distionaries use arbitrary key names that are strings. A complete review from the start is in order..


#12

Hey @mtf and @bibleman13 ,

You've got a great discussion going here. For the record, the exercise you are discussing is For the Record.

I'm not coming down completely on either side, because I can see the merits of either approach. In fact, the SCT will pass either one. But unfortunately, the SCT will balk if the user outputs labeling information along with the data.

Prior to arriving at this stage in the Python track, the user has learned to iterate through the items in a dictionary via A Day at the Supermarket. By this stage, the user has also been informed that the dict type is unordered.

An advantage to explicitly naming each key within a single loop is that it forces the value associated with the "name" key to display first for each dictionary, which makes it clear whose grade data follows.

The double loop approach in more general and concise, but since dictionaries are unordered, the "name" may not appear first, which makes the output confusing. However, that does not settle the matter, because we could place the keys in a list and iterate through that list in the inner loop to control the order of output of items from the dictionaries. This is less concise than looping through the dictionary keys directly, but it allows for future expansion of the dictionaries. For instance, if we wished to allow for additional grade categories, such as "projects" or "presentations", to be added to the dictionaries on the fly, we could write functions to handle adding the new keys to the dictionaries and updating the list of keys accordingly. But, then we might consider going further by refactoring the entire system to use an object oriented approach.

We can continue to discuss this, but I fear that we are now off-topic, having drifted away from the original issue ...


#13

Point taken, and well prefaced. Thank you.


#14

Well... Great discussion.
I decided to make the lists complete, but even when the output seemed to look great, codeacademy decided not to grade it as a proper answer.

students = [lloyd, alice, tyler]

student in students - for each one of them

for student in students:
#ptinting out all in one
print "%s: ""homework:"" %s, ""quizzes:"" %s, ""tests:"" %s" % (student["name"], student["homework"], student["quizzes"], student["tests"])

OUTPUT:
Lloyd: homework: [90.0, 97.0, 75.0, 92.0], quizzes: [88.0, 40.0, 94.0], tests: [75.0, 90.0]
Alice: homework: [100.0, 92.0, 98.0, 100.0], quizzes: [82.0, 83.0, 91.0], tests: [89.0, 97.0]
Tyler: homework: [0.0, 87.0, 75.0, 22.0], quizzes: [0.0, 75.0, 78.0], tests: [100.0, 100.0]

Looks good, but the codeacademy says: "
Oops, try again. Did you print out each student's name? It looks like "Lloyd" wasn't printed."

So I decided to go with an easy answer:

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

OUTPUT:
Lloyd
homework: [90.0, 97.0, 75.0, 92.0]
quizzes: [88.0, 40.0, 94.0]
tests: [75.0, 90.0]
Alice
homework: [100.0, 92.0, 98.0, 100.0]
quizzes: [82.0, 83.0, 91.0]
tests: [89.0, 97.0]
Tyler
homework: [0.0, 87.0, 75.0, 22.0]
quizzes: [0.0, 75.0, 78.0]
tests: [100.0, 100.0]
And it says that it's ok :confused:


#15

Hi, @maionhigh ,

When you submit code, Codecademy puts it through a submission correctness test (SCT) to catch errors and to determine whether it conforms to the specifications given in the exercise instructions. There is some degree of freedom regarding what can pass the test, but realistically, there are limits on the what improvements on the solution the SCT can accommodate.

While the output in your first example is great, it goes beyond what the SCT recognizes as matching the exercise specifications.

When you post code, you should format it so that we can see indentation and other details. See How do I format code in my posts?.


#16