You are over-increasing the total.

Notice there are two plus signs and an equal sign. That is all the operations that are going to take place with that statement.

```
>>> a = 0
>>> a += a + 5
>>> a
5
>>> a += a + 5
>>> a
15
>>> a += a + 5
>>> a
35
>>> a += a + 5
>>> a
75
>>>
```

The key to this is recognizing the expression, `a + 5`

. What ever value `a`

holds will be incremented by 5. Now we take that value and return it to `a += (expression value)`

and you see where this is going.

The purpose of the compound operator, `+=`

is to help us avoid this exponential growth, and concentrate upon the linear step value.

```
a += 5
```

Now we have what can be trusted to increment a in step values of 5.

Aside

We can build a term generator factory function for any step value and term n (sort of; need to iron out some details)…

```
>>> def a_plus_d_seq(d):
def seq(n):
a = list(range(n + 1))
for i in range(n):
a[i + 1] = a[i] + d
return a[n]
return seq
>>> fives = a_plus_d_seq(5)
>>> fives(0)
0
>>> fives(1)
5
>>> fives(2)
10
>>> fives(3)
15
>>> fives(4)
20
>>>
```

Ironed out. Term `n`

will indeed be correct where n > 0 and term 1 is 0.

```
>>> def a_plus_d_seq(d):
def seq(n):
a = list(range(n + 1))
for i in range(n):
a[i + 1] = a[i] + d
return a[n - 1]
return seq
>>> fives = a_plus_d_seq(5)
>>> fives(4)
15
>>> fives(1)
0
>>>
```

Taking it a bit further, let’s return the term, and the sequence up to that term…

```
>>> def a_plus_d_seq(d):
def seq(n):
a = list(range(n + 1))
for i in range(n):
a[i + 1] = a[i] + d
return a[n - 1], a[:-1]
return seq
>>> fives = a_plus_d_seq(5)
>>> fives(4)
(15, [0, 5, 10, 15])
>>> sixes = a_plus_d_seq(6)
>>> sixes(6)
(30, [0, 6, 12, 18, 24, 30])
>>>
```

If this appears to be over one’s head, don’t let it get to you. Right now you are learning the basic mechanics this is built from. Focus on that and when you finsh the track come back. It will make much more sense by then.

And with all the ironing out of the serquence generator we finally come up to the point where we can press it into service to generate the sequence the OP code sample produces…

```
>>> def foo(d):
def seq(n):
a = list(range(n + 1))
for i in range(n):
a[i + 1] = 2 * a[i] + d
return a[n - 1], a[:-1]
return seq
>>> fives = foo(5)
>>> fives(1)
(0, [0])
>>> fives(2)
(5, [0, 5])
>>> fives(3)
(15, [0, 5, 15])
>>> fives(4)
(35, [0, 5, 15, 35])
>>> fives(5)
(75, [0, 5, 15, 35, 75])
>>>
```

Gotta love math and programming together. Just astounds me the stuff we can come up with.

On the maths front, this falls under the concept of series and sequences which in Canada is explored very loosely in grade school, and comes up more seriously around grade 10 or 11 matric algebra. General math covers the topic but then abandons it. The academic route would be the way to go if maths are of any interest.