Digit_sum A little help here


#1



why isn't that working


nums=[]
def digit_sum(x):
    if len(str(x))>1:
        a=str(x)
        for char in a:
            nums.append(int(char))
        print(sum(nums))
    else:
        return x


#2

from the instructions:

Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number's digits

if i now want the digit_sum of 434, nothing gets returned.

Also, for validation the function will be called several times (not the whole script) so place nums = [] inside your function


#3

Thanks !:sweat_smile:


#4

issue resolved? If so, well done :slight_smile: i just gave a small hint and you solved it yourself :slight_smile:


#5

It turns out , it was the "print" statement that confused me .

I appreciate your help .


#6