Answer to Question #266876 in Python for kaavya

Question #266876

Reduce the digits:



You are given a positive integer N, write a program to repeatedly add the digits of the number until the number becomes a single-digit number.



Input:



The input should be a single line containing a single-digit number.



Output:



The output should be a single line containing a single-digit number.



Explanation:



In the example, the given number is 92. As the number is more than a single digit, repeatedly add the digits like



9+2=11



1+1=2

1
Expert's answer
2021-11-16T05:21:38-0500
def digSum(n):
 
    if (n == 0):
        return 0
    if (n % 9 == 0):
        return 9
    else:
       return (n % 9)
 
# Driver program to test the above function
n = 92
print(digSum(n))


#Solved by J@$ur_h@ckeR

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS