Practice makes perfect - Digit_sum


#1


Hi, I have an error with this script. It says "Your function fails on digit_sum(434). It returns None when it should return 11", but in fact it does return 11. Any ideas? Thanks!


def digit_sum(n):
    total = 0
    n = str(n)
    for i in n:
        total += int(i)
    print total

n = 1234
digit_sum(n)


#2

Hi have just changed "print total" by "return total" and now it works


#3

That's great! Happy coding! :smile:


#4

Thanks! :slight_smile:


#6