Programming Examples

Python program that receives a Fibonacci series term and returns a number telling which term it is


Write a Python program that receives a Fibonacci series term and returns a number telling which term it is . for instance, if you pass 3, it return 5, telling it is 5th term; for 8, it returns 7.

Solution

fib=[]
a,b=-1,1
c=0
ind=int(input("Enter any Element : "))
while c<=ind:
    c=a+b
    fib.append(c)
    a,b=b,c
#print(fib)
print("Element  ",ind," Found at :",fib.index(ind)+1,"Position")
Output

Enter any Element : 8

Element   8  Found at : 7 Position

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad