If you come across any unexpected problems, check the VibrantNotes Status for help. Check
Relayed
Loading Scripts...

Python program to print 20 terms of Fibonacci series.

Python program to print 20 terms of Fibonacci series. Class 11 Sumita Arora Numerical.
Python
Lang : Python
'''
0
1  
1  
2  
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
'''

# Solution

first = 0 second = 1 print('0') print('1') for i in range(1, 19): third = first + second print(third) first, second = second, third
Let's break down the code step by step:

1. first = 0 and second = 1: These are variables that store the first two numbers of the Fibonacci series.

2. print('0') and print('1'): These lines simply print the first two numbers of the series.

3. for i in range(1, 19): This loop is used to calculate and print the next 18 terms of the Fibonacci series. The loop starts from 1 and goes up to 18.

4. Inside the loop:
  • third = first + second: third is the sum of the last two numbers (first and second).
  • print(third): Prints the current Fibonacci number.
  • first, second = second, third`: Updates the values of first and second for the next iteration. It's a way of shifting to the next two numbers in the series.

So, the loop continues, adding the last two numbers to get the next one, printing it, and updating the values to move on to the next calculation. This process repeats until you have printed a total of 20 terms (including the initial '0' and '1').

Getting Info...

1 comment

  1. If you found this code to be helpfull, then don't forget to do a comment '👍'.
We value your input but ask that you refrain from spreading hate or disclosing sensitive data. Your comment will be carefully reviewed by our admin team before it appears.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.