#38636: python 輕鬆解


flyerfly1234@gmail.com (圤駿希)


利用str的特性來取到剩一位數。

while True:
    n = int(input())
    if n==0:
        break
    n = str(n)
    while len(n)>1:
        total = 0
        for i in n:
            total = total + int(i)
        n = str(total)
    print(n)