Python Program for Fibonacci Series
Here you will get the program code of Python program for Fibonacci Series. Here we are taking the n value from the user, calculating the Fibonacci series using for loop and if-else, and printing the result.
Fibonacci series is the sequence of the addition of last two preceding numbers.
for example:
The first 10 number’s Fibonacci series are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
Example Code of Python Program for Fibonacci Series
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #Python Program to Print Fibonacci Series n = int(input("Input the value of 'n': ")) # First and Second number a = 0 b = 1 # check if number is valid if n <= 0: print("Please enter a positive integer") else: print("Fibonacci series:") for i in range(n): print(a,end=' ') c = a + b # change values a = b b = c |
Output
Input the value of ‘n’: 15
Fibonacci series:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Check out our other Python Programming Examples