Can someone please explain this part of the code?


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

students = [lloyd, alice, tyler]
class_avg = get_class_average(students)
print class_avg
print get_letter_grade(class_avg)

#2

What do you understand? What is it you are struggling with?

If you include those details, we can much more tailor suite the explanation to your need. Otherwise, we might focus on the right thing, so please include this information


#3

where is the arguement “classs_list” being used?
and is the get_letter_grade giving the grade of the class?


#4

class_list is the function parameter:

# function deceleration with parameter class_list
def get_class_average(class_list):

then at function call we supply an argument for the parameter:

# list of students, which we are going to use at function call
students = [lloyd, alice, tyler]
# function call with argument students
# the argument at function call gets passed along to the function parameter
class_avg = get_class_average(students)

here:

print get_letter_grade(class_avg)

yes, in this case get_letter_grade is used to get the letter grade of the class average. otherwise, class_avg wouldn’t be a good variable name

but get_letter_grade only purpose in life is to convert number grade to letter grade, so it could also be used for a single student or a class of any size.


#5

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