The Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. The simplest form of the Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, etc.
The series was named after Leonardo Fibonacci, an Italian mathematician who introduced it in his book Liber Abaci in 1202.
The Fibonacci series has many applications in mathematics, particularly in the field of combinatorics. It also appears in nature in the spiral arrangement of leaves, seeds, and petals.
The Fibonacci series is generated by starting with 0 and 1 and then adding the two previous numbers to get the next number in the series.
def fibonacci(n): a = 0 b = 1 if n == 1: print(a) else: print(a) print(b) for i in range(2,n): c = a + b a = b b = c print(c) n = int(input("Enter the value of 'n': ")) fibonacci(n)
Enter the value of 'n': 9
0 1 1 2 3 5 8 13 21
- First, we take the number of terms from the user.
- Then we initialize the first two terms of the series to 0 and 1.
- Next, we use a for loop to iterate from 2 to the number entered by the user.
- In the loop, we add the previous two terms to get the next term.
- We then update the first and second terms to be the second and third terms, respectively.
- Finally, we print the series.