Practice makes perfect - Digit_sum


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


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


That's great! Happy coding! :smile:


Thanks! :slight_smile: