Check Arithmetic Progression

Take three numbers and check if they are in arithmetic progression.

AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 5 of 10
check-arithmetic-progression.py
1# Take three numbers
2a = float(input("Enter first number: "))
3b = float(input("Enter second number: "))
4c = float(input("Enter third number: "))
5
6# Check AP
7if (b - a) == (c - b):
8 print("Arithmetic progression")
9else:
10 print("Not an arithmetic progression")

Output

Enter first number: 2
Enter second number: 4
Enter third number: 6
Arithmetic progression

Enter first number: 2
Enter second number: 5
Enter third number: 6
Not an arithmetic progression

What's going on

In AP, difference between consecutive terms is constant.

Key Concepts:

Check if (b - a) == (c - b)
Common difference must be same
Simple equality check