4. Digit Sum


#1



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


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)):
        b.append(a[i])
    #print b
    for i in b:
        s += int(i)
    print s


#2

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.


#3

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