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/ Explanation:

Enter any Element : 8

Element   8  Found at : 7 Position

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad