15.4 digit_sum


#1



I am trying to create a code that applies to any number of any length. Is it true for my code?
Sorry for the confusing list of variables


def digit_sum(n):
    m = str(n)
    p = len(m)
    b = 0
    k = []
    for letters in m:
        if p > 0:
            
            letters = int(m[b])
            p -= 1
            b += 1
            k.append(letters)
            s = sum(k)
    return s


#2

2 posts were merged into an existing topic: Digit sum


#4