Computing the Average. Why we did float(len(grades)) to pass?


The code below is perfectly fine but why does it ask me to set float(len(grades)) instead of len(grades) when answer from both are same and how can length be of type float?


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

def grades_sum(scores):
    return sum(scores)
print grades_sum(grades)

def grades_average(grades):
    return grades_sum(grades)/**float(len(grades))**

print grades_average(grades)



The division operator / produces the quotient of its operands
where the left operand is the dividend
and the right operand is the divisor.

Either the dividend or the divisor should be a float
to get a =float= result....


Got you..
Integer / Integer = Integer
Integer / Float = Float
Float / Integer = Float
Float / Float = Float
And average is got to be float so at least one variable needs to be of float type..
Thank you for your help..
Is that really you in your profile picture? :relaxed:


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