Part of the whole 8/9 not understanding result


My code works but I want to have a better understanding of why we have an empty list for result in the get_class_average function. I’m not clear on how or if the result.append line is affecting this as well as the return line.

It is working but I want to make sure I understand it better.

def get_class_average(class_list):
    results = []


In order to compute a class average, we need a list of all the student weighted averages. results is the list that our code will build. Once the list is constructed we can take an average of the values it contains.


Ok, I think I can understand. Let me know if this is right. The results = [] is being modified by the code below where we are appending that list with the get_average function & so when I print the get class average function & put my students list in the spot for class_list, it carries that down into the student spot of results.append(get_average(student)) & then returns the result. I refreshed my understanding with append & that is the part that wasn’t making sense.

def get_class_average(class_list):
results = []
for student in class_list:
return average(results)

print get_class_average(students)
print get_letter_grade(get_class_average(students))


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