# Python For GCSE Sequences With Python

This is a relatively simple exercise that uses Python to explore simple arithmetic sequences. In Maths, the topic is called 'Finding the nth term of a sequence'.

### A Example

Output the first 10 terms of the sequence n + 2.

Here is a program that completes this task.

```for n in range(1, 11):
term = n + 2
print(term)
```

Output the first ten terms of the sequence, 20 - n

You should get, (19,18,17,16,15,14,13,12,11,10).

Output the first ten terms of the sequence, 5n + 4 (this means 5 times n, add 4)

You should get, (9,14,19,24,29,34,39,44,49,54).

Output the first ten terms of the sequence, 1/2n + 1 (this means 0.5 times n, add 1)

You should get, (1.5,2,2.5,3,3.5,4,4.5,5,5.5,6).

Output the first ten terms of the sequence, 3n - 3

You should get, (0,3,6,9,12,15,18,21,24,27).

### B Example

Work out the rule for the following sequence and write a program to generate the first 10 terms of the sequence.

4, 6, 8, 10, 12, ...

To work out the rule for the sequence, we start by writing a table something like the following. In the first row, we write some values for n, 1 to 5.

On the row labelled 1, we write the terms of the sequence in order.

On the row labelled 2, we work out the difference between each term and the previous one.

On the third row, multiply each value of n by the difference.

On the fourth row, see what you need to add to or subtract from the value in the third row to reach the term.

n12345
1Term4681012
2Difference to previous 2222
3n * difference246810

Our program needs to multiply by the difference (found in row labelled 2) and then do the addition or subtraction (row labelled 4).

```for n in range(1, 11):
term = n * 2 + 2
print(term)
```

Work out the rule and write a program to produce the following sequence, 5,9,13,17,21,...

Work out the rule and write a program to produce the following sequence, 3,15,27,39,51,...

Work out the rule and write a program to produce the following sequence, 3.5,6.5,9.5,12.5,...

## Extra Questions

Output the first ten terms of the sequence, n2

You should get, (1,4,9,16,25,36,49,64,81,100).

Output the first ten terms of the sequence, n modulus 2. What do you notice about the odd and even terms?

You should get, (1,0,1,0,1,0,1,0,1,0).