Answer to Question #302135 in Python for Rishu Pandey

Question #302135

Ram is given a positive integer N. He wishes to convert this integer into a single numeral . He does so by repeatedly adding the numerals of the number until there is only a single numeral . Help Ram by providing the single - numeral number finally obtained .


Input

The input is a single line containing a positive integer N.


Output


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


Explanation


In the example, the given number is 545.

As the number is more than a single numeral, repeatedly add the numerals like


5 + 4 + 5 => 14

1 + 4 => 5


So, the output should be 5.



Sample Input 1

545

Sample output 1

5


Sample Input 2

111

Sample output 2

3


1
Expert's answer
2022-02-24T08:03:17-0500
sum = 10
num = int(input("Input number: "))
while (sum > 9):
    sum = 0
    while (num != 0):
        sum = sum + num % 10  # sum of all digits
        num = num // 10
    num = sum
        
print("Single-numeral number: ", sum)

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