Pell Series
Generate Pell series (0, 1, 2, 5, 12, ...).
AdvancedPhase 6 - Category 4: Mathematical CombinationsExample 10 of 10
pell-series.py
1# Take n2n = int(input("Enter number of terms: "))34# Generate Pell series5if n <= 0:6 print("Invalid input")7elif n == 1:8 print("0")9elif n == 2:10 print("0 1")11else:12 a, b = 0, 113 print(a, b, end=" ")14 for i in range(2, n):15 c = 2 * b + a16 print(c, end=" ")17 a, b = b, c18 print()
Output
Enter number of terms: 8 0 1 2 5 12 29 70 169
What's going on
Pell series: P(n) = 2*P(n-1) + P(n-2).
Key Concepts:
Start with 0, 1
Each next = 2*previous + previous-1
Special recurrence relation
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum