Stuck in review


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

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

def print_all(grades):
    print(grades)
    print(grades_sum(grades))
    print(grades_average(grades))
    print(grades_variance(grades))
    print(grades_std_deviation(variance))
print_all(grades)


#2

The issue should be here:

The function name here

is print_grades. Call it and print it. Like this:

print print_grades(grades)

I hope this helps! :wink:


#3

I have updated, but still getting "Oops, try again. It looks like not all grades were printed! Make sure you are printing ech one on their own line." the output is here:
100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
1045.5
80.4230769231
334.071005917
18.2776094147
None
I can't pass through this stage.


#4

Please, post your updated code.


#5

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

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

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
p = variance / (len(scores))
return p

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

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


#6

You removed the print_all function? It doesn't matter :wink:

Okay, see this loop.

You should return grade and not return grades as you have it.


#7

Thanks, I have done that, but still the same result.


#8

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

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

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
        p = variance / (len(scores))
    return p

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

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

[100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
1045.5
80.4230769231
334.071005917
18.2776094147
None
every print call in one line, but the site interpreter says otherwise. please help.


#9

No, you didn't do as suggested.

Replace with

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

#10

Thanks, I have done the changes you suggested:
def print_grades(grades): for grade in grades: return grade
The code:
grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] def
print_grades(grades): for grade in grades: return 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 p = variance /
(len(scores)) return p def grades_std_deviation(variance): return variance
** 0.5 variance = grades_variance(grades) print(print_grades(grades))
print(grades_sum(grades)) print(grades_average(grades))
print(grades_variance(grades)) print(grades_std_deviation(variance))

but still there are ERRORS -
Oops, try again. It looks like not all grades were printed! Make sure you
are printing ech one on their own line.


#11

Okay, I will do a full recap and show you in full code because your last change reflected my last suggestion, but left out my first.

Please, see below.

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       #<----- Here

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
        result = variance/len(scores)
    return result
print grades_variance(grades)

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


print print_grades(grades) #<------ Here
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(variance)

Please note that python is indentation sensitive and you should learn to format it on the forum for ease.


#12

Thank you very much, Now I got it. I took me few hours with your help.


Review
#13

You're welcome. :wink:

Have fun coding!


#14

I try the same method it shows some error

Traceback (most recent call last):
File "python", line 40, in
File "python", line 30, in grades_std_deviation
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'float'

could u help in this matter?


#15

I see that you are having a TypeError as the logged by the error message. Do you mind copying and pasting your "well-formatted" code here?!

Thank you! :slight_smile:


#16

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