How to create a list containing an arithmetic progression?

Question:

Here’s an example of what I’m trying to achieve:

Example of what I'm trying to achieve

What I’m tring to do is make the sum of a starting number X, and sum it by Y, and with each sum, add the numbers to a previously empty list:

lst = []

i = -0.5
tot = 0.025
while i <= 100:
    tot = tot + i
    i = i + 1

a = tot
print("value: ",tot)
print(a)
lst.append(a)
print(lst)

Though I’m unable to keep them as individual numbers, and they just get clumped together.

Asked By: Saulo Manoel

||

Answers:

This is really about applying an incrementing multiplier to Y, so it is more suitably implemented by iterating over a range of multipliers.

To produce 4 items, for example:

i = -0.5
tot = 0.025
lst = [i + tot * m for m in range(4)]
Answered By: blhsing
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.