-3

I'm doing this problem Add Digits in recursion way. Why does it return None?

def addDigits(num):
    """
    :type num: int
    :rtype: int
    """
    shit = str(num)
    n = len(shit)
    if n == 1:
        return num
    else:
        num = 0
        for i in xrange(n):
            num += int(shit[i])
        addDigits(num)
Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
dlwlrma
  • 808
  • 2
  • 10
  • 21

1 Answers1

1

You need to return the value of the recursive call in the last line:

return addDigits(num)

Without such a return you silently return None

trincot
  • 317,000
  • 35
  • 244
  • 286