Do You Need to Find Fibonacci Numbers ?

The Fibonacci Series is a simple but fundamental series that remains the basis of multiple natural occurrences. It includes adding the previous two numbers of the series to get the next number of the series, starting with 0 and 1. So, now that we know the first and second numbers, the third number is obtained by adding 0 and 1 giving 2 and the fourth number is the sum of the second and third numbers (1 and 2 respectively) giving us 3 and so on. The series goes on like this:

0,1,1,2,3,5,8,13,...

A program to print the first n Fibonacci numbers can be easily written with one 'for loop'. Python's easy assignment of values features makes switching of values possible without a buffer variable.

Here's the code:
def Fibno():
	n1 = 0 #Two Starting Numbers
	n2 = 1

	terms = int(input("Enter number of terms: "))#Let user decide how many numbers of the series he wants to get

	print(f"{n1}\n{n2}")

	for i in range(2,terms):
	    sum = n1 + n2
	    print(sum) 
	    n1,n2 = n2,sum #Changing the values such that n1 becomes n2 and n2 becomes sum


OUTPUT:

When the code is executed, the output would look something like this...

Enter number of terms: 10
0
1
1
2
3
5
8
13
21
34
>>> 

and these are the first 10 numbers of the Fibonacci Series. A simple program can give you nature's most important series.

Comments