4. digit_sum (error using sum)


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096#


Your function fails on digit_sum(434). It returns None when it should return 11.


I haven't been able to figure out what is wrong with my code.


def digit_sum(n):
    n = str(n)
    numbers = []
    
    for char in n:
        numbers.append(int(char))
    
    print sum(numbers)


#2

Hi @wamplify,

The sum function is not the problem. You can use it for this exercise.

Instead of this ...

    print sum(numbers)

... you need to return the result, as follows ...

    return sum(numbers)

#3

Thanks! I figured it was probably a silly mistake.


#4