def listsum(numlist):
if len(numlist) == 1:
return numlist[0]
else:
return numlist[0]+listsum(numlist[1:])
print(listsum([1,3,5,7,9]))
用Python实现递归
最新推荐文章于 2023-04-07 18:38:40 发布
def listsum(numlist):
if len(numlist) == 1:
return numlist[0]
else:
return numlist[0]+listsum(numlist[1:])
print(listsum([1,3,5,7,9]))