7. The Variance


I got this error message while I was trying a solution I found in the forums
Traceback (most recent call last):
File "python/cli_runner.py", line 152, in
File "/root/adapter/runners/python/base_runner.py", line 46, in start
File "python/cli_runner.py", line 77, in handle_command
but I only have 25 lines of code

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

def print_grades(grades):
    for grade in grades:
        print grade

def grades_sum(grades):
    total = 0
    for grade in grades: 
        total += grade
    return total
def grades_average(grades):
    sum_of_grades = grades_sum(grades)
    average = sum_of_grades / float(len(grades))
    return average

def grades_variance(scores):
    for score in scores:
        variance=variance+(average - score) ** 2
    return results
print grades_variance(grades)


Save your code and refresh the page. Maybe that will jog things.


The sum_of_grades is more likely to be a float which makes converting a counting number to a float rather odd, semantically speaking.

float(sum_of_grades) / len(grades)

I could go along with very comfortably. The former makes no sense and looks rather arbitrary and misleading.

Technically, this value should already be a float, so it would be up to the grades_sum() function to make this happen.

total = float(0)

would set the ball in motion. The data does contain a float, so this is moot on the face of it, but if we assumed there were no floats, this would cover it.


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