Python Program to Convert Integer into a Single Numeral


 Single Digit Number

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 finaly 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 1

111

Sample Output 1

3

Code:

def findSum(n):
    n=str(n)
    total=0
    for i in n:
        total+=int(i)
    strTotal=str(total)
    if len(strTotal)>1:
        findSum(total)
    else:
        print(total)
        
n=input()
findSum(n)

Comments

Popular posts from this blog

CODING ASSIGNMENT 4

CODING PRACTICE 11 Music Page

CCBP Static Website Coding Assignment 2 Solution | Yoga Page