Hello too!
I really cant understand what im doing wrong here?

def digit_sum(n):

    for item in str(n):
        total = 0
        total = total + int(item)
    return total
print digit_sum(1234)

I have 4, but need sum of 1234 for example..
Please help )


shrijan23 was also stuck on this problem, how can (s)he help you then? Helping while stuck on something, is really difficult, it would have been better if you had made your own topic. Beside, if many people reply with a problem to the same topic, it becomes confusing who is helping and who has a problem, and whom is replying to whom

The problem is that total gets assigned zero each iteration of the loop, so what you add tot total in the first iteration of the loop, won't persist because in the second iteration total gets assigned zero again.


Thank you! Now I understood all.