Python Practice › Loop Programs › Program 56
Fibonacci numbers up to 55
Write a Python program to print the first 11 Fibonacci numbers (0 to 55).
Output
0 1 1 2 3 5 8 13 21 34 55
Approach
- Build a list starting [0, 1] and append the sum of the last two.
Solution
fib = [0, 1]while len(fib) < 11: fib.append(fib[-1] + fib[-2])print(*fib)Output
0 1 1 2 3 5 8 13 21 34 55
Line by line
Line 3
fib[-1] and fib[-2] are the last two values.
Line 4
*fib passes the items separately, so they print with spaces.
Learn the concept
New to this topic? Read the lesson, then come back.