Computing the Average


#1

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)
`


#2

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


#3

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.


#4

got it!

understand

Thanks


#5

should i just paste this n


#6

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.


#7