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


#1



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


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?


@leonhard.wettengmx.n


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)


#2

@oonyx,

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....


#3

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:


#4

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