Python program to find the type of the progression and the next successive member of the three successive members of a sequence.

For the above Python program to find the Arithmetic and Geometric Progression of a sequence, you need to understand that An arithmetic progression (AP) is a sequence of numbers such that the difference of any two successive members of the sequence is a constant. For instance, the sequence 3, 5, 7, 9, 11, 13, . . . is an arithmetic progression with common difference 2. For this problem, we will limit ourselves to arithmetic progression whose common difference is a non-zero integer. On the other hand, a geometric progression (GP) is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, . . . is a geometric progression with common ratio 3. For this problem, we will limit ourselves to geometric progression whose common ratio is a non-zero integer.

def my_sequence(array):
  if array[0]==array[1]==array[2]==0:
    return "Wrong Numbers"
  else:
    if array[1]-array[0]==array[2]-array[1]:
      n=2*array[2]-array[1]
      return "Arithmetic Progression Sequence, "+'Next number of the sequence: '+str(n)
    else:
      n=array[2]**2/array[1]
      return "Geometric Progression Sequence, " + 'Next number of the sequence:  '+str(n)

print(my_sequence([4,6,8]))
print(my_sequence([5,7,9]))
print(my_sequence([7,10,15]))
Sample Output:
Arithmetic Progression Sequence, Next number of the sequence: 10
Arithmetic Progression Sequence, Next number of the sequence: 11
Geometric Progression Sequence, Next number of the sequence:  22.5