用嵌套函数求1+(1+2)+(1+2+3)+...(1+2+3+......100)
时间: 2024-01-09 20:21:56 浏览: 73
以下是使用嵌套函数求1+(1+2)+(1+2+3)+...(1+2+3+......100)的Python代码:
```python
def nested_sum():
def love(a):
s = 0
for i in range(1, a+1):
s += i
return s
sum = 0
for i in range(1, 101):
sum += love(i)
return sum
result = nested_sum()
print(result) # 输出:171700
```
阅读全文