Q.

(a). Write a program that receive the index and return the corresponding value.

(b). Write a program that receives a Fibonacci term. And return and returns a number telling which term it is .


You can understand by Watching video :-



Answer :-

(a).

a = eval (input('Enter the list ='))
b = int (input ("Enter the index number ="))
if b< len(a):
    print ("value is =", a[b])
else :
    print ("index out of range")

(b).

term= int (input ("Enter Fibonacci Term ="))
fib = (0,1,1)
for i in range(term):
    fib = fib + ( fib [ i + 1] + fib [ i + 2 ],)
for j in range(len(fib)):
    if term == fib[ j ] :
        break
if j == len(fib)-1:
    print("Not Exist in Fibonacci Series ")
else :
    print("Fibonacci Series :- ", fib [ 0 :j +1] )
    print()
    print("This is ",j + 1,"th term of Fibonacci ")

Output :-

(a)

Enter the list = [1,2,3,4,5,6,7,8,9]
Enter the index number = 8
Value is = 9

>>> 

Enter the list = [12,78,69,52,23,32,41]
Enter the index number = 7
Index out of range

>>> 

(b)

Enter Fibonacci Term =55
Fibonacci Series :-  (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55)

This is  11 th term of Fibonacci

>>> 

Enter Fibonacci Term =30
Not Exist in Fibonacci Series

>>> 


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. this and Q1 have different solution for the same thing. should we write (term) or (term-2), in fact i think it should be (term-3). please correct this

    ReplyDelete
    Replies
    1. You can write term -3 but for some students it will become to hard to understand.

      Delete
  2. a = eval (input('Enter the list ='))
    b = int (input ("Enter the index number ="))
    if b< len(a):
    print ("value is =", a[b])
    else :
    print ("index out of range")

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post