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.

FAQs for the Codecademy Python exercise Part of the Whole:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

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

Need broader help or resources about Python in general? Go here!

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

Learn more about how to use this guide.

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

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • 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 (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

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


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:


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


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.

Ok I added it anyway.

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:

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)
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.


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

print (“Lloyd: grade = %s, percent = %s”) % (get_letter_grade(get_average(lloyd)), get_average(lloyd))
print (“Alice: grade = %s, percent = %s”) % (get_letter_grade(get_average(alice)), get_average(alice))
print (“Tyler: grade = %s, percent = %s”) % (get_letter_grade(get_average(tyler)), get_average(tyler))
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?