给定自然数 n,编写函数,求其各位数字之和,如数 1234 各位数字之和为10。编写函数,重复上述过程,直至得到 1~9 之间的某个数。(python)
def nSums(num):
while num>=10:
sums = 0
num_list = []
for i in str(num):
num_list.append(i)
for j in num_list:
sums = sums + int(j)
num = sums
return num
print(nSums(1234567))
如果有帮助,记得采纳点赞哦~