Using While for digit_sum exercise


Hi there,

Tried using this code to run the digit_sum exercise, but not sure why it won't work. I figured out another way, but interested to know why this didn't work.


def digit_sum(n):
    n = str(n)
    i = 0
    z = 0
    while i <= len(n):
        z = int(n[i:(i+1)])
        z =+ z
        i =+ 1
        return z


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.