Computing the Average, why is this wrong?


#1

https://www.codecademy.com/courses/python-intermediate-en-7mgOa/1/2?curriculum_id=4f89dab3d788890003000096

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

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


#2

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:


#3

I fixed it. Thanks bandit :slight_smile:

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

grades_average(grades)


#4

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