This post shows how to print the Fibonacci series in Python. The Fibonacci series is a sequence where each number is the sum of the two preceding numbers, starting from 0 and 1.
Print Fibonacci series in Python:
Explanation:
We start with the first two terms, 0 and 1, and repeatedly add them together to generate the next term, up to however many terms the user requests.
Python Program to Print Fibonacci Series
n = int(input("Enter number of terms: "))
a, b = 0, 1
print("Fibonacci Series:")
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
Output:
Enter number of terms: 8
Fibonacci Series:
0 1 1 2 3 5 8 13
See more classic algorithm walkthroughs in our Interview Prep section.
