Weight and See


Error Message: Oops, try again. get_average(alice) returned 97.5 instead of the expected 91.15

def get_average(student):
    for homework in student:
        return average(student['homework'])
    for quizzes in student:
        return average(student['quizzes'])
    for tests in student:
        return average(student['tests'])
    return .1 * homework + .3 * quizzes + .6 * tests


Hi @objectjumper86545 ,

The for loops that you have do not assign the necessary values to your variables in preparation for the final return statement. In fact, the following two lines of code and the other two similar blocks of code would cause the function to return before processing is completed for all of the relevant data ...

    for homework in student:
        return average(student['homework'])

Replace the above with ...

    homework = average(student['homework'])

Perform corresponding replacements for the other two for loops as well.

This statement is fine as is ...

    return .1 * homework + .3 * quizzes + .6 * tests

EDITED (February 8, 2017) to add the following:
When a return statement is executed, execution of the function terminates, and a result is passed back to whatever statement called the function.


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