In this program, we will get the Fibonacci series between 0 to 20.
Steps to solve the program
- Create two variables and assign their values equal to 0 and 1 respectively.
- Create another variable count and assign its value equal to 0.
- While the count variable is less than 20 print the num1.
- Add num1 and num2 and assign their addition to the n2 variable.
- Change the value of num1 with num2 and num2 with n2.
- Add 1 to the count variable.
- Print the Fibonacci series.
num1 = 0
num2 = 1
count = 0
while count < 20:
print(num1,end=" ")
n2 = num1 + num2
num1 = num2
num2 = n2
count += 1
Output :
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181