Fibonacci Series Program in Python
In this post, you will learn how to write Fibonacci series of program using Python.
The Fibonacci series are the sequence of number in which the next number is the sum of the previous two numbers. Fibonacci series was known hundreds of years before. The "Fibonacci" name came from the nickname "Bonacci".
We can easily remember Fibonacci Sequence using the Fibonacci Day, which is November 23rd. As 23rd November has the digits "1, 1, 2, 3" which is part of the sequence.
In the above image, the first two numbers are 0 and 1. So, according to the Fibonacci rule the third number is 1 (sum of 0 and 1). The fourth number is 2 and so on.
0 + 1 = 1 // 0, 1, 1
1 + 1 = 2 // 0, 1, 1, 2
1 + 2 = 3 // 0, 1, 1, 2, 3
2 + 3 = 5 // 0, 1, 1, 2, 3, 5
0 ,1 , 1, 2, 3, 5, 8, 13, 21, 34....
series = int(input("How many number of series? "))
x1, x2 = 0, 1
count = 0
if series <= 0:
("Invalid: Please enter a positive integer")
elif series == 1:
print("Fibonacci series upto ",series,":")
print(x1)
else:
print("Fibonacci series sequence:")
while count < series:
print(x1)
xth = x1 + x2
x1 = x2
x2 = xth
count += 1
Output of the above code
How many number of series? 30
Fibonacci series sequence:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
Related Articles
How to read xml file in PythonPython Spell Checker Program
Python remove punctuation from string
How to convert Excel to CSV Python Pandas
How to read data from excel file using Python Pandas
How to read data from excel file in Python
Python read JSON from URL requests
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert xml to dict
Python convert dict to xml
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers