Python Practice › Loop Programs › Program 6
Fibonacci series up to 20
Write a Python program to print the Fibonacci series from 0 to 20.
Output
0 1 1 2 3 5 8 13
Approach
- Keep two variables and advance them until the value passes 20.
Solution
a, b = 0, 1while a <= 20: print(a, end=" ") a, b = b, a + bprint()Output
0 1 1 2 3 5 8 13
Line by line
Line 4
Both values update at once, so no temporary variable is needed.
Learn the concept
New to this topic? Read the lesson, then come back.