#38636: python 輕鬆解


flyerfly1234@gmail.com (圤駿希)

學校 : University College London
編號 : 234049
來源 : [150.116.149.189]
最後登入時間 :
2024-03-10 20:40:12

利用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)