# Need Help on 7 variance

#1

``````def grades_variance(grades):
variance = float(0)
variance+= float((i-average)**2)
return variance``````

#2

I took a kind of round about way to break down and analyze the problem using this sketch:

``````grades = [8, 8, 6, 3, 7, 7, 1, 5]
g_sum = sum([x*1.0 for x in grades])
print g_sum
print avg
h = [(x - avg)**2 for x in grades]
print h
k = sum(h)/len(h)
print k``````

The console output looks like this:

``````45.0
5.625
[5.640625, 5.640625, 0.140625, 6.890625, 1.890625, 1.890625, 21.390625, 0.390625]
5.484375``````

The final value matches what is expected from the SCT when it supplies the above set of grades.

In the sketch I use list comprehensions, but we can reconstruct it with for statements if so desired. From this we can rewrite our grades_sum function,

``````def grades_sum(scores):
s = [x*1.0 for x in scores]
return sum(s)``````

All the above is doing is making sure that every value in the list is converted to a float before the returned sum. The grades_average function makes a quick call to this one and returns a simple quotient of the return value and the list length.

``````def grades_average(scores):
``````def grades_variance(scores):