Answer to Question #310386 in Python for sai krishna

Question #310386

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-03-12T12:46:34-0500
sum = 10
number = int(input("Input number: "))
while (sum > 9):
    sum = 0
    while (number != 0):
        sum = sum + number % 10  
        number = number // 10
    number = sum   
print("\nSingle numeral:", 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