Computing the average: why won't my float work?


#1


Whenever I use the function at the end of the page, my window returns : Object of type 'float' has no len(). why is that? I followed the instructions alongside the window as mentioned.


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

def grades_sum(scores):
    total=0
    for i in range(0, len(scores)):
            total+=scores[i]
    return total
    #80.42
def grades_average(grades):
    grades=grades_sum(grades)
    avg=grades/float(len(grades))
    print avg
    
       
    
    
    
    
    
print grades_average(grades)


#2

@andrewjf

You have to be careful when you use the same name for the same things because you start to get into namespace issues.

Correct this issue and your code will function properly.

Also, there is a neat built in function called sum() that calculates a list of numbers total.

a = [1, 2, 3, 4, 5, 6]
print(sum(a))  
# 21