Python Practice › Loop Programs › Program 39

Fibonacci series of n terms

EasyLoop Programs · 39 of 90

Write a Python program to print the first n terms of the Fibonacci series.

Advertisement
Input
n = 12
Output
0 1 1 2 3 5 8 13 21 34 55 89 

Approach

  1. Loop n times, printing and advancing the pair.

Solution

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

More loop programs

← All 90 Loop Programs

Leave a Comment