5: computing the average


#1



Oops, try again. grades_average([1]) returned 1045.5 instead of the expected: 1.0


whats wrong with my code,anyone?


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


#2

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

def grades_sum(grades):
total = sum(grades)
return total

print grades_sum(grades)

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


#3

thanks but i've tried your code,i still get an error message

Oops, try again. grades_average([3, 2]) returned 522.75 instead of the expected: 2.5


#4

here it is
def grades_average(grades):
average = 0
average = grades_sum(grades) / float(len(grades))
return average
print grades_average(grades)


#5

did you indent it properly


#6
def grades_average(grades):
    average = 0
    average = grades_sum(grades) / float(len(grades))
    return average
print grades_average(grades)

here it is, with proper indentations!


#7

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