Question:

Write a program to take two integer inputs from console. Number and N and print nth term in fibonacci series for the inputted Number. 

Fibonacci series :0,1,1,2,3,5,8,13,21,34,55,89,144 and so on.

Example input :

3

Example output:

21 

source code

				
					n1 = int(input())  
n2 = int(input())
n_terms=n1+n2
n_1 = 0  
n_2 = 1  
count = 0  
l=[]
if n_terms == 1:  
    l.append(n_terms)
else:  
    while count <= n_terms:  
        l.append(n_1) 
        nth = n_1 + n_2  
        n_1 = n_2  
        n_2 = nth  
        count += 1

indexs=l.index(l[n1])
print(l[indexs+n2])

				
			

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *