8 Standard Deviation


#1

Hello, my first post here, I've checked previous discussions but got none the wiser. Why didn't my code work?

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))
    # use float() to make sure the average will return decimal places
    return average

def grades_variance(grades):
    average = grades_average
    variance = 0
    for i in grades:
        sqdf = (average - i ) ** 2
        variance = variance + sqdf
    result = variance / float(len(grades))
    return result

def grades_std_deviation(variance):
    result = variance ** 0.5
    return result

variance = grades_variance(grades)
print(grades_std_deviation(variance))


#2

@demiaca

Can you print your code please?


#3

Sorry, just added contents to my original blank post. First time poster, didn't realise it went off after hitting 'enter'.


#4

@demiaca

Can you tell us what error message you get with the link to the exercise please?


#5

In the console I got this:

Traceback (most recent call last):
File "python", line 32, in
File "python", line 23, in grades_variance
TypeError: unsupported operand type(s) for -: 'function' and 'int'

At the bottom of the screen, the error message is this:

Oops, try again. Your code appears to raise an error, see the console window for the error message!

This is the exercise: https://www.codecademy.com/en/courses/python-intermediate-en-7mgOa/2/2?curriculum_id=4f89dab3d788890003000096

I am really stuck, having checked all previous discussions and didn't seem to find any solutions. Please help, and thanks in advance!


#6

Hi this part

def grades_variance(grades):
    average = grades_average
    variance = 0
    for i in grades:
        sqdf = (average - i ) ** 2
        variance = variance + sqdf
        result = variance / float(len(grades))
    return result

here

average = grades_average

you should put average equal to the call function of grades_average() with the argument grades like that

average = grades_average(grades)

#7

It works! Thank you!!!


#8

It works for me.

def grades_std_deviation(variance):
    sqr_root = variance ** 0.5
    return sqr_root

variance = grades_variance(grades)
print grades_std_deviation(variance)