Very basic Riemann sum in Python

I really suggest you to take a look over the documentation. A simple loop would solve your problem:

a = [1, 2, 3, 4, 5]
results = []
for i in range(len(a)-1):
    results.append((a[i]+a[i+1])/2)

print(results)

Output: [1.5, 2.5, 3.5, 4.5]

Leave a Comment