Python Practice › Loop Programs › Program 39
Fibonacci series of n terms
Write a Python program to print the first n terms of the Fibonacci series.
Input
n = 12
Output
0 1 1 2 3 5 8 13 21 34 55 89
Approach
- Loop n times, printing and advancing the pair.
Solution
n = 12a, b = 0, 1for _ in range(n): print(a, end=" ") a, b = b, a + bprint()Output
0 1 1 2 3 5 8 13 21 34 55 89
Line by line
Line 3
The loop runs exactly n times, one term per pass.
Learn the concept
New to this topic? Read the lesson, then come back.