Python 中的累积和程序

2025年16月16日 | 阅读 2 分钟

什么是累加和?

累加和的意思是“到目前为止的总和”。累加和的定义是指给定序列中,随着更多项的添加而递增或变大的和。累加和的一个实际例子是游泳池中水量不断增加。

示例

程序:1

输出

10, 25, 45, 70, 100

程序:2

输出

1, 3, 6, 10, 15, 21, 28, 36, 45, 55

程序 3:用户自定义程序

输出

enter the no of elements in list: 10
enter the element1: 2
enter the element2: 3
enter the element3: 8
enter the element4: 6
enter the element5: 45
enter the element6: 32
enter the element7: 56
enter the element8: 32
enter the element9: 14
enter the element10: 25
Original list is: [2, 3, 8, 6, 45, 32, 56, 32, 14, 25]
Cumulative sum list is: [2, 5, 13, 19, 64, 96, 152, 184, 198, 223]