Python Practice › Loop Programs › Program 6

Fibonacci series up to 20

EasyLoop Programs · 6 of 90

Write a Python program to print the Fibonacci series from 0 to 20.

Advertisement
Output
0 1 1 2 3 5 8 13 

Approach

  1. Keep two variables and advance them until the value passes 20.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment