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
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:
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').
- 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').