- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to check we can make arithmetic progression from sequence in Python

Suppose we have a list of numbers called nums. We have to check whether the elements present in nums are forming AP series or not. As we know in AP (Arithmetic Progression) series the common difference between any two consecutive elements is the same.

So, if the input is like nums = [9,1,17,5,13], then the output will be True because if we sort them, it will be [1,5,9,13,17] and here common difference is 4 for each pair of elements.

To solve this, we will follow these steps −

nums := sort the list nums

if number of elements in nums > 1, then

const := nums[1] - nums[0]

otherwise,

return True

for i in range 0 to size of nums -1, do

if nums[i+1] - nums[i] is not same as const, then

return False

return True

## Example (Python)

Let us see the following implementation to get better understanding −

def solve(nums): nums = sorted(nums) if len(nums) > 1: const = nums[1] - nums[0] else: return True for i in range(len(nums)-1): if nums[i+1] - nums[i] != const: return False return True nums = [9,1,17,5,13] print(solve(nums))

## Input

[9,1,17,5,13]

## Output

True

- Related Questions & Answers
- Program to check subarrays can be rearranged from arithmetic sequence or not in Python
- Program to find removed term from arithmetic sequence in Python
- Finding the missing number in an arithmetic progression sequence in JavaScript
- Program to check how many queries finds valid arithmetic sequence in Python
- Program to find number of ways we can select sequence from Ajob Sequence in Python
- Program to check whether we can make k palindromes from given string characters or not in Python?
- C program to find the sum of arithmetic progression series
- C++ program to check we can make two strings equal by swapping from third string
- Missing Number In Arithmetic Progression using C++
- Program to check we can form array from pieces or not in Python
- C Program for N-th term of Arithmetic Progression series
- Program to check whether we can reach last position from index 0 in Python
- Longest Arithmetic Sequence in C++
- Program to check we can rearrange array to make difference between each pair of elements same in Python
- Find the missing number in Arithmetic Progression in C++