I am trying to write a recursive method as follows, but I am getting SyntaxError: invalid syntax, I wonder what I am doing wrong
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
class Solution(object):
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
return self.addDigits(x=sum(i for i in str(num)) if x%9<10:
Note: I am learning recursion in python, therefore rather than knowing how to solve problem, I would love to learn what I am doing wrong in my implementation.
numbut you're passingxas the kwarg?