I think that I am doing this right?


I am stuck on the chapter 8 (loops) on section 4 (digit_sum) in Python:

My code is supposed to add up the digits of a number, however this message pops up:
Your function fails on digit_sum(434). It returns None when it should return 11.

I'm expecting an 11 to be returned, but it is return none in stead.

def digit_sum(n):
    digits = []
    index = len(str(n))
    sUm = 0
    for number in range(0, len(str(n))):
    for digit in digits:
        sUm += int(digit)
    print sUm
print digit_sum(434)


your code prints the sum, it doesn't return it


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