This forum is now read-only. Please use our new forums at discuss.codecademy.com.

446 points
Picture
Submitted by
Tommy Zhou
over 4 years ago

Can anyone help me? Thanks! (Solved! 100% right!!)

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 gradesaverage(grades):
sum
ofgrades = gradessum(grades)
average = sumofgrades / len(grades)
return average

def grades_variance(grades,average):
variance = 0
for g in grades:
variance += ((average - g) ** 2)
return variance / len(grades)

print gradesvariance(grades, gradesaverage(grades))

I do not know why my code did not work and i tried other people's solution, but it kept saying "ooops, try again".
Hope someone can give me a right solution.
Thanks


3 votes

permalink

Hi,

Maybe it is your indentation?

Here is the whole 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):
    average=grades_average(scores)
    variance=0
    for score in scores:
        variance += ((average-score)**2)
        final_variance=variance/float(len(scores))
    return final_variance
print grades_variance(grades)

508 points
52f9bf4f631fe9ea81000e57_63238566
Submitted by
Niloufer Othman
over 4 years ago

4 Comments

52f9bf4f631fe9ea81000e57_63238566 Niloufer Othman over 4 years ago

the instructions i got told me to use scores as an argument.

Picture Tommy Zhou over 4 years ago

thank you very much

52f9bf4f631fe9ea81000e57_63238566 Niloufer Othman over 4 years ago

no problem.. i hope it worked for you this time

530ff5418c1cccbf54001bd3_216566758 salvador alvarez over 4 years ago

tanks!!!!!!!!!


0 votes

permalink

can i ask why you decided to use two arguments in your definition for grades_variance?

here is my solution that worked, hopefully it will help you

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

508 points
52f9bf4f631fe9ea81000e57_63238566
Submitted by
Niloufer Othman
over 4 years ago

2 Comments

Picture Tommy Zhou over 4 years ago

Can I have the whole code, cuz it still does not work . Thank you very much.

52a8bdca52f863d44e000e1b_594691430 Jack maher over 4 years ago

Tah very much brilliant code helped me out loads