Exam Statistics: Computing the Average


I don’t know what seem to the issue with my code, here"s the instruction;

Define a function, grades_average, below the grades_sum function that does the following:

Has one argument, grades_input, a list
Calls grades_sum with grades_input
Computes the average of the grades by dividing that sum by float(len(grades_input)).
Returns the average.
Call the newly created grades_average function with the list of grades and print the result.

Here’s my code:

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
#total = 0
def grades_sum(scores):
total = 0
for grade in scores:
total += grade
return total
#print total
print grades_sum( grades )

def grades_average(grades_input):
sum_of_grades = grades_sum(grades)
average = sum_of_grades / float(len(grades))
return average
print grades_average(grades)
Here’s the error message am getting:

grades_average([3]) returned 80.42307692307692 instead of the expected: 3.0.

Am just not getting the strategy in this function definitions, is there any additional trick that I need to learn???


you need to use grades_input instead of grades


I had the same issue, but the comment from @ninjamoose91 helped me clarify my arguments in the average function. Thanks @ninjamoose91!