a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] 从前往后 求每三个数的平均数
时间: 2024-01-05 22:03:59 浏览: 91
任输入三个数,求得平均值,平均值程序
5星 · 资源好评率100%
以下是从前往后求每三个数的平均数的示例代码:
```python
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
averages = []
for i in range(0, len(a)-2, 3):
average = sum(a[i:i+3]) / 3
averages.append(average)
print(averages)
```
输出结果为:
```
[1.0, 4.0, 7.0, 10.0, 13.0, 16.0, 19.0, 22.0, 25.0]
```
阅读全文