5/9 Computing the Average - incorrect average


Here is my code:

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def grades_sum(scores):
    total = 0
    for i in scores:
        total += i
    return total
def grades_average(grades):
    average = grades_sum(grades) / len(grades)
    print average

and my error:

Oops, try again. You did not print the correct average. Double-check your code and make sure you print the average!

and a print screen for reference:

So how is my output a different average than codecademy is looking for?


There were two things that had to be fixed to meet with SCT expectations. The list we are given to work with contains a float so all our computations work as expected. But the SCT tries the program with a list of integers, so the result is an integer, not a float. We need to manually set this in our code.

The other issue is that the program needs to return the average, not print it. The SCT is expecting a number but is instead seeing none which is the standard response from Python when there is no return value from a function.

def grades_average(grades):
    average = float(grades_sum(grades)) / len(grades)
    return average


Thank you very much. That worked like a charm.


A post was split to a new topic: Not computing average