# FAQ: Learn Python: Student Becomes the Teacher - Part of the Whole

This community-built FAQ covers the “Part of the Whole” exercise in Codecademy’s lessons on Python.

## Join the Discussion. We Want to Hear From You!

Agree with a comment or answer? Like () to up-vote the contribution!

Want to take the conversation in a totally different direction? Join our wider discussions.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

## Other FAQs

• This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
• This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try searching for it by clicking the spyglass icon () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().

one question:
I want to write a code in this exercise to get the averages of each student whit the “get_average()” function and put them in a list like this:
class_list = [lloyd, alice, tyler]
results = [80.55, 90.15, 79.9]

I wrote the below code, but I get this answer “None, None, None”

for student in class_list:
results = [ ]
result = get_average(student)
print results.append(result)

what’s the problem?

`.append()` does not return anything so the statement prints `None`.

1 Like

I am stuck. And now I am worried programming is not for me. Because with this lesson is when it get’s hard, so far our hand was held as it said in the text.

Can someone help me without providing the solution? In a way that I learn. For now I am stuck.

I don’t understand this:
For each `student` item in the `class_list` , calculate `get_average(student)` and then call `results.append()` with that result.

Finally, return the result of calling `average()` with `results` .

There is no student item in class_list because the example only told me to to write the function with it as an argument.

This is my code.

``````def get_class_average(class_list):
results = []
for get_average(student) in class_list:
results.append()
return average(results)
``````

The `class_list` is the global object, `students` which contains references to three dictionaries. In a dictionary, a key-value pair is known as an item, but in this instance, `item` is referring to each referenced object, in turn. That would make it an `element` but we get the idea.

There is when we pass the `students` object as an argument of the call to `get_class_average`; as in,

``````print(get_class_average(students))
``````

You should have a `students` object in with your global data…

``````students = [lloyd, alice, tyler]
``````

That line would, one thinks raise an exception.

``````for student in class_list:
results.append(get_average(student))``````

Thanks.

There is nowhere mentioned that I should have a line “students = [lloyd, alice, tyler]”

1 Like

I think we do create it at some point earlier, but it may not be carrying over. Just insert that object underneath the three dictionaries so it is grouped with the data.

No, not even when fetching the code solution it is present. I think you might be refering to a later lesson.

That’s odd. It is needed for this function so I can’t see it being in a later lesson.

Let’s take this one issue at a time.

For each `student` item in the `class_list` , calculate `get_average(student)` and then call `results.append()` with that result.

Okay, I understand the bold one. It instructs me to write “for student in class_list:”
But then I do not undersatand how to write the rest of the code. How to calculate?

You should have a function already written for `get_average`. We call it from within the loop, on each student in turn…

``````for student in class_list:
results.append(get_average(student))
``````

That will populate the `results` list with three different average grades.

I don’t quite understand what is happening here. Could you explain?

What does results.append does?

How can there be a “results” when that is not a variable that has been defined earlier? Calling implies a function…how can we call a function that has not been defined?

This is the code that the code solution provides:

for student in class_list:
student_avg = get_average(student)
results.append(student_avg)
return average(results)

1 Like

Just inside the function, we declare,

``````results = []
``````

Then we proceed with the loop to iterate over the class list. Each calculated average is appended to the list.

I DID THIS:

def get_class_average(class_list):
results =
for student in class_list:
n = get_average(student)
results.append(n)
return average(results)

print (“Class average: %s”) % round(get_class_average([lloyd, alice, tyler]), 1)

Which returns this:

Lloyd: grade = B, percent = 80.55
Alice: grade = A, percent = 91.15
Tyler: grade = C, percent = 79.9
Class average: 83.9

Would you provide a link to the exercise? Why did you use a for loop in the function, yet four separate print() statements?

This is a bit late but you say to create the list students in the lesson after this one. It is the first step of the next lesson.

This did in fact work for me, but it did NOT return your below result. It actually returned only the letter “B”. I’m also curious as to why ‘n’ is used instead of student.

Could you please offer more insight?

Thanks!