Exam statistics - just tell me what I'm doing wrong


#1



Link: https://www.codecademy.com/courses/python-intermediate-en-7mgOa/1/1?curriculum_id=4f89dab3d788890003000096

Oops, try again. Make sure to print the result of the grades_sum() function.

...errr, wat? I did print the result and I have done everything right, I know I'm very close there is just one small thing missing that I'm doing wrong. Just tell me and explain it to me because I have spent two hours here and I cannot figure it out. THANNNNNNKS

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

def grades_sum(scores):
    total = 0
    for item in scores:
        total += item
    return total
    
    print grades_sum(scores)


#2

Because of the indentation, this line looks like it is inside the code block of the function above it. Remove the indent on that line.

Your function should be returning the arithmetic mean (the average) but is returning the sum without dividing by the count.

return total / len(scores)

There is the temptation to later on declare a float. We can elliminate any need for that by declaring in this function since it is the first in a chain of functions.

total = float(0)

or

total = 0.0

It's possible this function has not come up yet in any previous lessons, which would explain why the author forces floats into existence by writing one of the data points as a float... 50.5. If our code is correct all the way through, we can forego the concern over floats for this exercise. But in future we will learn that it is never safe to assume our data will contain any floats, which is why we explicitly declare it as early as we can (as shown above, in the grades_sum function).


#3

I have made the small corrections but my code is still not passing. I calculated the length of the light grades instead of the argument scores because I want to divide by the number of values in the list i.e. find the mean. Here is my new code.
`
def grades_sum(scores):
total = 0.0
for item in scores:
total += item
return total / len(grades)

print grades_sum`
It gives me this error: Oops, try again. It looks like your grades_sum function doesn't properly compute the sum of all the grades! It returned X instead of X for grades_sum([X])
X is a different number each time.


#4

Its fine I just had to add (grades) to print grades_sum and grades instead of scores everywhere else.


#5

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