78. Problem to get a list of Fibonacci numbers from 1 to 20.

In this Python list program, we will get a list of Fibonacci numbers from 1 to 20 with the help of the below-given steps.

List of fibonacci numbers:

Steps to solve the program
  1. Create an empty list.
  2. Calculate the Fibonacci series of numbers from 1 to 20 using for loop with the range function.
  3. Add that series to the empty list.
  4. Print the list to see the result.
				
					#Creating empty list
list1 = []

num1 = 0
num2 = 1

for i in range(1,21):
    list1.append(num1)
    n2 = num1+num2
    num1 = num2
    num2 = n2

#Printing output
print(list1)
				
			

Output :

				
					[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 
144, 233, 377, 610, 987, 1597, 2584, 4181]
				
			

Related Articles

Calculate the factorial of each item in the list

Reverse all the numbers in a given list

Leave a Comment