2
I need to create a recursive function that takes a number n
integer and returns the sum of the digits of this number.
I made the following code but it’s giving None
:
def somadig(n, s = 0):
if n > 10:
d = n%10
s += d
return somadig(n//10,s)
print(somadig(120))
In this case the result would be 3?
– Wictor Chaves