7/9 Invalid Syntax


#1

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

print grades_variance(grades)

Somehow the print statement is invalid syntax. What am I doing wrong?


#2

The parameter variable is scores.

variance needs to be accumulated:

variance += ...

Remove the first ( so you have an even match, (( ...))


#3
def grades_variance(scores):
    average = grades_average(scores)
    variance = 0
    for score in scores:
        variance += (average - score) ** 2
    result = variance / float(len(scores))
    return grades_variance(grades)

RuntimeError: maximum recursion depth exceeded
What might be wrong?


#4

There's the recursion. Calling the same function from within its body. Change the line to read,

    return result