4. Digit Sum



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

Expected it to work, considering I've been playing around with it on 'spyder' and it works fine on there, even if I isolate each line of the code. Just not working when moving back to codecademy - probably just a formatting error I can't see!

Replace this line with your code. 
def digit_sum(n):
    """Returns the sum of all of n's digits"""
    s = 0
    a = str(n)
    b = []
    print a
    for i in range(0, len(a)):
    #print b
    for i in b:
        s += int(i)
    print s


The instructions are asking that you return the sum, currently you are printing it which is why the error is saying you are returning none instead of 11.


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