Repetitive Addition Of Digits
I solved this problem geeksforgeeks, where we need to add the given digit till the output come in single digit.
Question: https://practice.geeksforgeeks.org/problems/repetitive-addition-of-digits2221/1#
Solution:
class Solution:
def SumOfDigit(self,N):
sum_digit = 0
for digit in str(N):
sum_digit += int(digit)
return sum_digit
def singleDigit(self, N):
#code here
if N < 10:
return N
return self.singleDigit(self.SumOfDigit(N))
Above code pass all test scenario.
0 Comments