Write a recursive function that accepts a number as its argument and returns the sum of digits.

Source Code

def sumDigits(n):
    if (n < 10):
        return n
    else:
        return n % 10 + sumDigits(n // 10)

#calling the function
number = 23456
print('Sum of digits of number',number,'is',sumDigits(number))

Output

Sum of digits of number 23456 is 20