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

Why does this happen?

x = raw_input("Type a positive number")

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



Hi @bytepro57181 ,

You have this instead of a return statement ...

print suma

Make the correction, then to see the output, instead of this ...


... make the function call as part of a print statement, as follows ...

print digit_sum(x)


you need to return inside the function
and then print


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