例子:
def my_sum1(n):
if n<=0:
return 0
else:
return my_sum1(n-1)+n
# res = my_sum1(10)
# print(res)
lst = []
def my_sum2(n):
if n==1:
return 1
else:
return my_sum2(n-1)+2
# res = my_sum2(3)
# print(res)
for i in range(1,11):
lst.append(my_sum2(i))
print(lst)
print(sum(lst))
def my_sum(n):
sum = 0
for i in range(n):
sum += i