Exam Statistics (Pls help ^^)


#1

Hi,
I got the following problem. The editor / terminal got stuck on the list, which was written before, and not by me. I'm not sure if I can describe the problem without the code, so here you can see it for yourself:

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

def grades_sum(scores):

total = 0

for grade in grades:

    total += grade

return total

The taks in this exercise is:

On line 3, define a function grades_sum() that does the following:

1. Takes in a list of scores, **scores**
2. Computes the sum of the scores
3. Returns the computed sum

Call the newly created grades_sum() function with the list of grades and print the result.

Whenever I try to start this programme, it says:

Oops, try again.
It looks like your grades_sum function doesn't properly compute the
sum of all the grades! It returned 1045.5 instead of 338 for
grades_sum([86, 33, 76, 52, 46, 23, 22])

Well I thought it got stuck on the liste which is above, but whenever i delete that list, I get another error:

Oops, try again.
It looks like your grades_sum function doesn't properly compute the
sum of all the grades! It returned 1045.5 instead of 50 for
grades_sum([50])

I tried to make the list a comment, but get the same error. I tried this code in Python IDLE too, and it worked there.
This is actually the second time I got this kind of error, but last time I typed the code in a different way and it worked there, since it was way too complicated the way it was before, but I'm not sure how to deal with this one.

I would really appreciate it, if anyone would help ^^


#2

Hi first your for loops should be like that for grade in scores and don't forget to
print grades_sum(grades)


#3

Thank you very much! I didn't notice that part at all ^^
Totally my bad, thinking I was right and blaming the system for it :frowning: