Check Geometric Progression
Check equal ratios between three values. Students trace division guards, nested decisions, and why this simple geometric-progression test rejects zeros.
1# Take three numbers2a = float(input("Enter first number: "))3b = float(input("Enter second number: "))4c = float(input("Enter third number: "))56# Check GP (avoid division by zero)7if a != 0 and b != 0:8 if (b / a) == (c / b):9 print("Geometric progression")10 else:11 print("Not a geometric progression")12else:13 print("Cannot form GP with zero")
Output
Enter first number: 2 Enter second number: 4 Enter third number: 8 Geometric progression Enter first number: 2 Enter second number: 5 Enter third number: 8 Not a geometric progression
In this one
- Compare consecutive ratios
- Guard division by zero
- Understand implementation limits
How it works
- 1
Read the three floats.
- 2
Require nonzero a and b before division.
- 3
Compare b / a with c / b and print.
Edge cases
What if a is zero?
What if a is zero?
The outer guard prints the zero-related message before division.
Can float ratios have rounding trouble?
Can float ratios have rounding trouble?
Yes. Exact equality may be unsuitable for some decimal inputs.
What's going on
A geometric progression uses a constant multiplier between consecutive terms. This implementation compares b / a with c / b, so both denominators must be nonzero.
The outer guard prevents division by zero; the inner comparison checks the ratios. Input 2, 4, 8 passes with ratio two. The rejection message is a limitation of this division-based version, not a universal mathematical rule that zero can never occur in a progression.
What if a is zero? The outer guard prints the zero-related message before division.
Can float ratios have rounding trouble? Yes. Exact equality may be unsuitable for some decimal inputs.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which ratios are compared?
Pick an answer to check it.
Question 2
What if a is zero?
Pick an answer to check it.
Questions people ask
What if a is zero?
The outer guard prints the zero-related message before division.
Can float ratios have rounding trouble?
Yes. Exact equality may be unsuitable for some decimal inputs.
Which ratios are compared?
b / a and c / b.
๐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