7. The Variance


#1



Oops, try again. grades_variance([9, 8, 5, 5, 7, 8, 5, 0]) returned 9.765625 instead of the expected: 7.109375


Am I utilizing the for loop incorrectly?


def grades_variance(scores):
    average = grades_average(scores)
    variance = 0
    for score in scores:
        variance += (average - score) ** 2
        return variance
    total = variance / len(scores)
    return total
        
print grades_variance(grades)


#2

a function ends the moment a return keyword is reached

if a return keyword is reached in a loop, it will cause the loop to break

so your function ends to early


#4

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