Digit_Sum


#1

In Practice Makes Perfect: Digit_Sum, Codecademy told me my code returned an error, and sure enough, PyCharm tells me the same:

UnboundLocalError: local variable 'sum' referenced before assignment

I don't understand why. Here's the code:

def digit_sum(n):
    sum == 0
    for d in str(n):
        sum += int(d)
    return sum

#2

I expect that error message comes with a line number for when the problem occurred. You might want to consider what you meant that line to do and then look up examples for how to do it.