首页 > 编程语言 > 详细

python:递归算法求和1-100

时间:2018-06-30 21:40:53      阅读:587      评论:0      收藏:0      [点我收藏+]
#递归算法求和1-100
def qiehe():
def he(lis):
if lis == []:
return 0
return lis[0] + he(lis[1:len(lis)])
s = []
n = input("请输入数字:")
for i in range(1, int(n)):
s.append(i)
print(he(s))
qiehe()
def sum(max):
    if max <= 100 and max >= 0:
        return max +sum(int(max) - 1)
    else:
        return 0
print(sum(100))

 

python:递归算法求和1-100

原文:https://www.cnblogs.com/shishandeda/p/9248700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!