Logic Building
# Take three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
# Check AP
if (b - a) == (c - b):
print("Arithmetic progression")
else:
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
In AP, difference between consecutive terms is constant.
Key Concepts:
- Check if (b - a) == (c - b)
- Common difference must be same
- Simple equality check