Check Arithmetic Progression
Check whether three entered values form an arithmetic progression. A lesson on equal consecutive differences, input order, and floating-point comparisons.
1# Take three numbers2a = float(input("Enter first number: "))3b = float(input("Enter second number: "))4c = float(input("Enter third number: "))56# Check AP7if (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
In this one
- Compare consecutive differences
- Allow decreasing progressions
- Recognize float equality limits
How it works
- 1
Read a, b, and c.
- 2
Calculate b - a and c - b.
- 3
Print whether those differences are equal.
Edge cases
Does 6, 4, 2 pass?
Does 6, 4, 2 pass?
Yes. Both differences are minus two.
Do three equal numbers pass?
Do three equal numbers pass?
Yes. Both differences are zero.
What's going on
An arithmetic progression keeps the same difference from one term to the next. The program compares b - a with c - b in the entered order.
Input 2, 4, 6 passes because both differences are two. A decreasing sequence also works when both differences are equal and negative. The code compares floats exactly, so decimal rounding can affect some mathematically equal differences.
Does 6, 4, 2 pass? Yes. Both differences are minus two.
Do three equal numbers pass? Yes. Both differences are zero.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which property defines this check?
Pick an answer to check it.
Question 2
Does 6, 4, 2 pass?
Pick an answer to check it.
Questions people ask
Does 6, 4, 2 pass?
Yes. Both differences are minus two.
Do three equal numbers pass?
Yes. Both differences are zero.
Which property defines this check?
Equal consecutive differences.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum