digit_sum


#1

I don't understand why this doesn't work...

def digit_sum(n):
    a = sum(n)
    return a

What am i doing wrong?!?

the output i'm getting is:

Oops, try again. Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a "'int' object is not iterable" error.


#2

OH!

got it :smile:

def digit_sum(n):
    n = str(n)
    
    n_lst = []
    
    for char in n:
        n_lst.append(char)
        
    total = 0
    
    for char in n_lst:
        num = int(char)
        total += num
        
    return total

I'll be honest, some of the descriptions of the tasks are very well written. and yes, English is my first language!