Please Help with Code! Overlooked instructions?


When I submit this code, it returns: Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected.

I expected it to be the correct answer. I founded it rather odd that the sidebar said to use what seemed like a preexisting list, class, that I hadn't been asked to make before. Class also seemed to be a function, so I instead created a new list, class_list. Is that something that was overlooked, or was I supposed to put something like that into the code a while ago? Anyway, the only things I have changed about the code for Part 11 are the "def get_class_average" part at the very end at the class_list list. Please 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]

class_list = [lloyd, tyler, alice]

# Add your function below!

def average(numbers):
    total = sum(numbers)
    total = float(total)
    return total / len(numbers)

def get_average(student):
    homework = average(student["homework"]) * 0.1
    quizzes = average(student["quizzes"]) * 0.3
    tests = average(student["tests"]) * 0.6
    return homework + quizzes + 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'

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


your function should work for a class of any size (1, 2 or 3 students) supplied as argument on function call

Why do you not use the function parameter?


I'm sorry, I'm not following you.


where do i loose you?

I loose you so much you can't even answer a simple question:


I'm sorry, I'm just fairly new at this. Where should I have used a function parameter?



def get_class_average(students):

you have a function parameter students but you don't use it anywhere in the function, so you don't do anything with the argument which is what the error message is telling:

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

# function call
print get_class_average([alice])

the function always calculates the class average for 3 students, while we also want to be able to calculate the class average for 1 or 2 students


So... do I not need the class_list thing at all?

Here are the sidebar instructions:

Define a function called getclass_average that has one argument students. You can expect students to be a list containing your three students._
First, make an empty list called results.
For each student item in the class list, calculate getaverage(student) and then call results.append() with that result._
Finally, return the result of calling average() with results.

It seemed, it my eyes, to expressly state that one needed a "class list" already created (with class highlighted in the original text), but I guess the student parameter works for that, right? It seems to me that that is somewhat misleading. What would it look like if that problem were corrected?


no, you should use the function parameter instead

I didn't write the course, i am not going to discuss instructions. For you, its important to always question why you do something, like: i added a function parameter, should i use it and how? Think about what you are doing, don't take everything for granted from the instructions. Instructions won't be there forever


It worked! Thank you very much! I still feel like the instructions are somewhat misleading though, but I do understand why it wasn't working now.