Working on the grades_sum segment and can’t seem to move forward because I receiving an error code. I’ve copied this code into other IDE’s and it works just fine. Is this a bug or…?

Here’s the code:

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

total = 0
for i in scores:
total = total + i
print total

If you think it works just fine, then you’ve probably misunderstood what the code is supposed to do. I don’t think the function is supposed to print anything? Read the instructions again, what is the function supposed to do?

Also, mind the indentation when you post code.

got the same problem here.On returning
total = 0

total = 0
print total

none of the above functions work

I think you’re pretty much there. If you go with the second version of your code in terms of structure, you just need to generalize the inputs from grades to score and add the print to grade_sum(grades), it’ll work. My version for reference:
total = 0
for i in scores:
total = total + i

1 Like

Thanks

I had the exact same issue. Can someone explain why the print needs to be added when calling the function, rather than within the function (i.e., why we can’t do “print total” and then just call the function without print)? I seem to mess this up frequently so need to better understand the issue.

Hello everyone here’s my working code.

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

total = 0
for score in scores:
total =  total + score

```
4 Likes

I used this exact same code, except used i instead of score and I get this error

Oops, try again. It looks like your grades_sum function doesn’t properly compute the sum of all the grades! It returned 39 instead of 236 for grades_sum([39, 90, 27, 29, 7, 18, 26])

I had this same issue and it was because I used the wrong list to iterate over:

for item in scores:

HTH

hahah… have some mercy on new coders man!!

Thank you!
I did not realize I need to “return” in the function, and “print” the call.

Return the value in the function, then print the result of the call, like this:

``````> def grades_sum(scores):
>     total = 0
>     for score in scores:
>         total += score