【发布时间】:2020-01-26 03:25:23
【问题描述】:
def digit_sum(n):
'''(int)->number
Returns the sum of all the digits in the given integer, n'''
if n<10:
return n
return n%10 + digit_sum(n//10)
def digital_root(n):
'''(int)->number
Returns the resulting sum of the digits in the given integer until it reaches a single digit number; via digit_sum'''
while n>9:
n=sum(digit_sum(n))
return n
写了digit_sum的代码,然后用递归写了digital_root。我该怎么办?任何帮助表示赞赏!
【问题讨论】:
-
我真的很想知道,为什么教授讨厌循环?
-
可能是递归练习?
标签: python