Computing the Average, why is this wrong?


Traceback (most recent call last):
File "python", line 18, in
NameError: name 'grades' is not defined

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


You don't need this line,

and you have the right idea you just wrote this line a bit incorrectly,

should look like,

average = float(grades_sum(grades)) / len(grades) Because we want it to return a float of the sum of all the grades divided by the number of grades. :slight_smile:


I fixed it. Thanks bandit :slight_smile:

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



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