First N Terms of AP
Print first n terms of arithmetic progression (a, d).
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 9 of 13
first-n-terms-of-ap.py
1# Take inputs2a = int(input("Enter first term (a): "))3d = int(input("Enter common difference (d): "))4n = int(input("Enter number of terms (n): "))56# Print AP7print(f"First {n} terms of AP:")8for i in range(n):9 term = a + i * d10 print(term, end=" ")11print()
Output
Enter first term (a): 2 Enter common difference (d): 3 Enter number of terms (n): 5 First 5 terms of AP: 2 5 8 11 14
What's going on
AP: each term = first term + (position - 1) * difference.
Key Concepts:
nth term = a + (n-1) * d
Loop from 0 to n-1
Calculate each term
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum