4.digit_sum Why this isn't working?


#1

i can't find the problem here :frowning:
can someone help me?

def digit_sum(n):
....leen = len(str(n))
....mod = 10
....div = 1
....suum = 0
....tot = 0
....while leen > 0:
........suum = n % mod / div
........tot = tot + suum
........mod = mod * 10
........div = div * 10
........leen -= 1


#2

I found the problem! i wasn't returning anything.. heheh now it's working and look like this:
def digit_sum(n):
....leen = len(str(n))
....mod = 10
....div = 1
....suum = 0
....tot = 0
....while leen > 0:
........suum = n % mod / div
........tot = tot + suum
........mod = mod * 10
........div = div * 10
........leen = leen - 1
....return tot