Can you write a Python program to check a sequence of numbers is an arithmetic progression or not?
To refresh your memory, a sequence is a set of things (usually numbers) that are in order. In an Arithmetic Sequence the difference between one term and the next is a constant. In other words, we just add the same value each time.
For example, the sequence 5, 7, 9, 11, 13, 15 ... is an arithmetic progression with common difference of 2.
We can write an Arithmetic Sequence as a rule:
xn = a + d(n−1)
How would you write it using Python? Try it yourself. If you cannot figure it out, see code on the next page.
d = seq - seq
for index in range(len(seq) - 1):
if not (seq[index + 1] - seq[index] == d):
print(is_arithmetic([3, 7, 11, 15]))
print(is_arithmetic([3, 8, 11, 15]))
Write something about yourself. No need to be fancy, just an overview.