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
'''
本文标题:用递归的方法写一个求和函数
本文链接:https://www.haomeiwen.com/subject/llkutftx.html
网友评论