9/9 Help


#1

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(grades):
average = grades_average(grades)
variance = 0
for score in grades:
variance += ((average - score) ** 2)
variance /= float(len(grades))
return variance

def grades_std_deviation(variance):
return variance**0.5
variance = grades_variance(grades)

print "All the grades are: %s" % print_grades(grades)
print "The sum of all the grade is: %s" % grades_sum(grades)
print "The average of all the grades is: %s" % grades_average(grades)
print "The variance of the grades is: %s" % grades_variance(grades)
print "The standard deviation of the grades are: %s" % grades_std_deviation(variance)

Oops, try again. It looks like the sum of grades was not printed! Make sure you are printing it on its own line.


#2

Try this

print grades_sum(grades)
print grades_average(grades)
print grades_std_deviation(variance)

point it just print everything without the statements

Did it work?


#3

Yes, thank you. I was trying to add details but I guess not. Thank you :wink:


#4

Hello.

I am having the same exact problem. My code is the next one:

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(grades):
average = grades_average(grades)
variance = 0
for score in grades:
variance += ((average - score) ** 2)
variance /= float(len(grades))
return variance

def grades_std_deviation(variance):
return variance**0.5
variance = grades_variance(grades)

print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(variance)

The results I get are:

100
100
90
40
80
100
85
70
90
65
90
85
50.5
1045.5
80.4230769231
69.0504943648
8.30966271065
None

And I get an error message like the next one: Oops, try again. It looks like the sum of grades was not printed! Make sure you are printing it on its own line. The print_grades(grades) has no print statement before it to avoid a double print command (there is one inside th function).

How could I solve it? I am stuck in this exercise whose code I know is properly working...


#5

I have this seem problem... Any idea what is the reason?


#6

try this. i have commented what changed

rades = [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(grades):
    average = grades_average(grades)
    variance = 0
    for score in grades:
        variance += ((average - score) ** 2)/len(grades)
        # variance /= float(len(grades)) took this line out added it above
    return variance

def grades_std_deviation(variance):
    return variance**0.5
    
variance = grades_variance(grades)

print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print variance #printed variance instead of grades_variance(grades)
print grades_std_deviation(variance)

#7

hi

pleas help i have the same problem, here my code:

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

def print_calificaciones(calificaciones):
for calificacion in calificaciones:
print calificacion

def notas_sum(calificaciones):
total = 0
for calificacion in calificaciones:
total += calificacion
return total

def promedio_notas(calificaciones):
suma = notas_sum(calificaciones)
promedio = suma / float(len(calificaciones))
return promedio

def varianza_notas(calificaciones):
promedio = promedio_notas(calificaciones)
varianza = 0
for calificacion in calificaciones:
varianza = varianza + ((promedio - calificacion) ** 2)
varianza /= float(len(calificaciones))
return varianza

def calificaciones_std_desviacion(varianza):
varianza = varianza ** 0.5
return varianza

varianza = varianza_notas(notas)

print print_calificaciones(notas)
print notas_sum(notas)
print promedio_notas(notas)
print varianza
print calificaciones_std_desviacion(varianza)


#8

Do you want a Clean and Neat Code? Try Mine :smiley:
Hope It Helps. :smile:

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(grade):
sum_of_grades = grades_sum(grade)
average = sum_of_grades / float(len(grade))
return average

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

print grades_variance(grades)

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

variance = grades_variance(grades)

print "Grades:", print_grades(grades)

print "Grades Sum:", grades_sum(grades)

print "Grades Average:", grades_average(grades)

print "Grades Standard Deviation:", grades_std_deviation(variance)


#9

Tuve problemas similares, me acepto el siguiente codigo, suerte:v

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

def print_calificaciones(calificaciones):
for calificacion in calificaciones:
print calificacion

def notas_sum(calificaciones):
total = 0
for calificacion in calificaciones:
total += calificacion
return total

def promedio_notas(calificaciones):
suma = notas_sum(calificaciones)
promedio = suma / float(len(calificaciones))
return promedio

def varianza_notas(calificaciones):
promedio = promedio_notas(calificaciones)
varianza = 0
for notas in calificaciones:
varianza += (promedio - notas) ** 2
result = varianza / len(calificaciones)
return result

def calificaciones_std_desviacion(varianza):
result = varianza ** 0.5
return result

varianza = varianza_notas(calificaciones)

print notas
print notas_sum(calificaciones)
print promedio_notas(calificaciones)
print varianza_notas(calificaciones)
print calificaciones_std_desviacion(varianza)


#10
print print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(variance)

#11

I am having a problem with 'The variance' question . Is anyone able to see what I'm doing wrong?
This is the code I've used for that section.