Computing the Average


I believe I am getting the correct average results, but I keep getting an error:
Oops, try again. grades_average([2]) returned 80.42307692307692 instead of the expected: 2.0

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

What's wrong!

def grades_sum(numbers):
total = 0
for item in numbers:
total += item
return total

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

print grades_average(grades)


This post was flagged by the community and is temporarily hidden.


You are getting bad result for grades_average([2]) because you are using global variable grades instead of scores parameter in your function definition.

def grades_average(scores):
    sums = grades_sum(grades) # use scores instead of grades
    average = float(sums) / len(grades) # same here
    return average

Or change parameter name like @khanh.le said.


got it!




should i just paste this n


It won't work if you paste my code since there are errors :slight_smile: I have had put comments to explain what's wrong it this code, so follow them and you'll pass this exercise.