Digit_sum


#1



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

digit_sum(x)


#2

Hi @bytepro57181 ,

You have this instead of a return statement ...

print suma

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

digit_sum(x)

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

print digit_sum(x)

#3

you need to return inside the function
and then print


#4

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