Digit_sum


#1



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

I don't get it, when I try it in my python IDE it gives the correct result but it will also give None as well.


def digit_sum(n):
    result = 0
    b = str(n)
    for x in b:
        result = result + int(x)
    print result
    
n = 434

print digit_sum(n)


#2

you print the result, you should return the result


#3

Sir, you genius.

do you care to explain why this is an issue however? as the result is still the same?


#4

return and print do work differently, although the result might look the same. (due to that you use print on the function call)

The biggest issue is that what is returned is validated by the checking script to validate the code works correctly, without return the wrong thing is returned, causing an error


#5

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