Exercise 3.1: Variance

#1

Exercise 3.1: Variance

This code works correctly, I just don't understand why it works.

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

total = 0

return average

variance = 0
for score in scores:
variance += (average - score) ** 2
return variance / len(scores)

#2

scores holds the grades list. look:

``````def grades_variance(scores):
print scores

you pass grades as argument at the function call, so the function parameter (scores) now holds the list with grades

#3

Scores is just the name you give to the variable the function takes to do its things.
So when you call "grades_variance(grades)", scores becomes grades and the function uses that list to work with. If you called "grades_variance(someotherlist)", scores would become that other list and the function would use that instead.
So whenever you call it its like doing "scores = the thing you have inside brackets".

#4

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