python:递归算法求和1-100

#递归算法求和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))

 

posted @ 2018-06-30 21:28  狮山的达  阅读(10110)  评论(0)    收藏  举报