Fibonacci Series Recursively
Print Fibonacci series up to n terms recursively.
IntermediatePhase 3 - Level 1: Basic RecursionExample 9 of 10
fibonacci-series-recursively.py
1def fibonacci(n):2 if n == 0:3 return 04 if n == 1:5 return 16 return fibonacci(n - 1) + fibonacci(n - 2)78# Print series9n = int(input("Enter number of terms: "))10for i in range(n):11 print(fibonacci(i), end=" ")12print()
Output
Enter number of terms: 8 0 1 1 2 3 5 8 13
What's going on
Call fibonacci function for each index.
Key Concepts:
Loop from 0 to n-1
Call fibonacci(i) for each
Print each term
🔗Related Content
- 📖
Phase 3 - Learn Concepts
Review Phase 3 concepts and explanations
- 📝
Phase 3 - Quiz
Test your Phase 3 understanding with quiz questions
- 💻
Phase 3 - All Practice Problems
Explore all practice problems for Phase 3
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum