-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
  • 12,648
  • 3
  • 32
  • 70
dlwlrma
  • 758
  • 2
  • 7
  • 19

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
  • 263,463
  • 30
  • 215
  • 251