给定自然数 n,编写函数,求其各位数字之和,如数 1234 各位数字之和为10。编写函数,重复上述过程,直至得到 1~9 之间的某个数。(python)
1条回答 默认 最新
风铃扬音 2021-11-14 19:11关注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))如果有帮助,记得采纳点赞哦~
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报