這是對codewars.com一個挑戰,但我想不通,爲什麼這個while循環不起作用我不知道爲什麼這個while循環沒有停止迭代
def digital_root(n):
# Creating variable combine to have the sum
combine = 0
# as long as n is more than two numbers.
while n > 10:
# converting n to string to iterate
for i in str(n):
# getting the sum each element in n
combine += int(i)
# reset n to be equal to the combined result
n = combine
return combine
也,任何解決方案,可以理解,這裏是鏈接到挑戰 https://www.codewars.com/kata/sum-of-digits-slash-digital-root
請在這裏告訴我們一些背景。什麼是n?你想用這個功能實現什麼? –
n是一個數字,這裏是我想要實現的鏈接https://www.codewars.com/kata/sum-of-digits-slash-digital-root –