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 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
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
🔗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