4. The sum of scores Error


#1



Exercise 4 of 16. Exam Statistics
I did my code but got an error. I've read the code loads of time and it still doesn't work.


I get this error:
Traceback (most recent call last):
File "python", line 10, in
File "python", line 7, in grades_sum
UnboundLocalError: local variable 'total' referenced before assignment


I expected it to do the sum of all the grades. Thank you for any help you can provide!


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

total = 0

def grades_sum(score):
    for x in score:
        total += x
    return total
   
print grades_sum(grades)


#2

it seems the exercise calls the function, in which case total is not defined, place the declaration of total inside the function


#3

It worked :slight_smile: Thank you so much!


#4