Tribonacci Series
Generate Tribonacci series (each term is sum of previous three).
IntermediatePhase 6 - Category 4: Mathematical CombinationsExample 8 of 10
tribonacci-series.py
1# Take n2n = int(input("Enter number of terms: "))34# Generate Tribonacci5if n <= 0:6 print("Invalid input")7elif n == 1:8 print("0")9elif n == 2:10 print("0 1")11elif n == 3:12 print("0 1 1")13else:14 a, b, c = 0, 1, 115 print(a, b, c, end=" ")16 for i in range(3, n):17 d = a + b + c18 print(d, end=" ")19 a, b, c = b, c, d20 print()
Output
Enter number of terms: 8 0 1 1 2 4 7 13 24
What's going on
Each term is sum of previous three.
Key Concepts:
Start with 0, 1, 1
Each next = sum of previous three
Track last three terms
🔗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