用递归的方法写一个求和函数
2018-02-15 本文已影响0人
文扬量化
def sum(alist):
first,*other=alist
return first+sum(other) if other else first
print ( sum(range(1,101)) )
'''
输出:5050
'''
def sum(alist):
first,*other=alist
return first+sum(other) if other else first
print ( sum(range(1,101)) )
'''
输出:5050
'''