I think that I am doing this right?


#1



I am stuck on the chapter 8 (loops) on section 4 (digit_sum) in Python:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096


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))):
        digits.append(str(n)[number])
    for digit in digits:
        sUm += int(digit)
    print sUm
print digit_sum(434)


#2

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


#3

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