# Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

# Python Program To Check Whether The Sequence Is In Arithmetic Progression

A sequence is called to Arithmetic series when the difference between two consecutive numbers remains constant throughout the series. If we express the first term as `a` and the difference between the terms `d`, then we can generalize any arithmetic progressive series as `[a, a+d, a+2d, a+3d …,a+kd]`

In this article, we will create a Python program to check whether the given sequence is in Arithmetic Progression (A.P.) or not.

## Python Program To Check Whether A Sequence Is In Arithmetic Progression

``````def progression(l):
if len(l) == 1:
return True
else:
diff = l[1] - l[0]
for index in range(len(l) - 1):
if not (l[index + 1] - l[index] == diff):
return False
return Trueprint(progression([7, 3, -1, -5]))
print(progression([3, 5, 7, 9, 10]))``````

Output:

``````True
False``````

## Explanation

In the above program first, we verifying whether the length of the series is greater than one because there must be at least 2 elements in any Arithmetic series. Next, we are calculating the difference between the first two elements of the sequence then we are examining whether the difference is constant throughout the list by iterating over each element of the list if this evaluates to true the given list is in Arithmetic Progression.

PROGRAMS

# Latest Articles

Latest from djangocentral

## How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…

## DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…

## Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …