编写函数实现求 1+(1+2)+(1+2+3)+……+(1+2+3+4+……+n)的和。Python
时间: 2023-09-18 12:09:59 浏览: 470
vc.zip_4 3 2 1_earlierm8a_vc编写htons函数
def sum_of_series(n):
sum = 0
for i in range(1, n+1):
temp_sum = 0
for j in range(1, i+1):
temp_sum += j
sum += temp_sum
return sum
print(sum_of_series(3)) # 输出6+3+1=10
阅读全文