Part 9/9- Why do we have to define the list of students?


I got my code working, thanks to other people in the forum who posted about the same question...what I don't understand is the why.

Since we used students throughout the whole rest of the section without defining the student list, I don't understand why we have to define students=[lloyd,alice,tyler] at the end in order to get the class average/ average letter grade. If we do have to define it to print the class average, why didn't we have to define it before when we were using it in the functions for the the individual student average?

Thank you in advance for the help!!

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]

# Add your function below!
def average(numbers):
    return total/len(numbers)
    print total/len(numbers)

def get_average(student):
    return 0.1*homework+0.3*quizzes+0.6*tests

def get_letter_grade(score):
    if score>=90:
        return "A"
    elif score>=80:
        return "B"
    elif score>=70:
        return "C"
    elif score>=60:
        return "D"
        return "F"
print get_letter_grade(score)

print get_average(alice)

def get_class_average(students):
    for student in students:
    return average(results)

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



In lesson 8 (Part of the whole) it states -

Define a function called get_class_average that has one argument students. You can expect students to be a list containing your three students.

In lesson 9 it states -

Finally, print out the result of calling get_class_average with your students list. Your students should be [lloyd, alice, tyler].

You called something students in def get_class_average, but this is the first time you used the word 'students'. Now you make a list to explain what students is.

That is how I understood it, perhaps others can give another insight.

Hope that helps.


"why didn't we have to define it before when we were using it in the functions for the the individual student average?"

because all variables for the INDIVIDUAL students are already defined.
and now we have to calculate the average for the WHOLE class, thats why we need a list of all students to get the average of each and then the average of the class.

actually we could define this list earlier, just to call one student with its index, but that is the matter of the organization of this course.

I hope I've got your question right.


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