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))

猜你喜欢

转载自www.cnblogs.com/shishandeda/p/9248700.html
今日推荐