Check Geometric Progression
Take three numbers and check if they are in geometric progression.
AdvancedPhase 1 - Level 5: Creative / Tricky Logical ScenariosExample 6 of 10
check-geometric-progression.py
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
What's going on
In GP, ratio between consecutive terms is constant.
Key Concepts:
Check if (b/a) == (c/b)
Handle division by zero
Common ratio must be same
🔗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