Digit_sum(434)


#1



Hello everybody,
I'm having trouble with the digital_sum exercise of Practice Makes Perfect:

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/4?curriculum_id=4f89dab3d788890003000096
I think I already have the answer; however, I keep getting this error message:

Oops, try again. Your function fails on digit_sum(434). It returns None when it should return 11.

Here is my code:

n = raw_input('Enter number')
def digit_sum(n):
    n = str(n)
    s = 0
    for i in n:
        s = s + int(i)
    print s
digit_sum(n)


The weird part is that I've tried it with 434 and I do get the desired result of 11. Any help?


#2

The hint here is to return a value, not print it. If you wish to print, do it with the return value.

print (digit_sum(434))

#3

Thank you @mtf
hate to recognize it was a misreading mistake :stuck_out_tongue: