Oops, try again. get_average(alice) returned 80.55 instead of the expected 91.15


im stuck at this ex https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/1/2?curriculum_id=4f89dab3d788890003000096

no idea why it keeps getting stuck at this part.
Thanks in advance:)

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 average
def get_average(student):
    for student in students:
        return get_average


Why going trough the students list when you have the exact student in the function's parameter? (get_average(alice))

The logic is fine, I think it messed up when you returned the result still inside the for cycle.


what i tried to do is to use a for loop to compute the score of all 3 students at once. not just alice.

i shifted the return result to out of the for loop. but now the answer is 79.9... still wrong


i somehow managed to solve the issue with the following code:

def get_average(students):
for student in students:
return get_average

but i dont really get the logic, anybody can to explain??


You could go trough the students list if you wanted, yes, but that's not what the instructions are asking for.

Write a function called get_average that takes a student dictionary (like lloyd, alice, or tyler) as input and returns his/her weighted average.

In further lessons they'll ask you to define a new function that calculates the average of the whole class, you're a few steps ahead already.


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