Solution Review: Corresponding Fibonacci Number
This review provides a detailed analysis of how to find the corresponding element at a given index in the Fibonacci series.
We'll cover the following...
Solution #1: Iterative Method
Python 3.5
def fibonacci(testVariable):fn0 = 0fn1 = 1for i in range(0, testVariable):temp = fn0 + fn1# Setting variables for next iterationfn0 = fn1fn1 = tempreturn fn0# Driver CodetestVariable = 7print(fibonacci(testVariable))
Explanation
In the iterative method, we keep track of the two previous elements using the variables fn0 and fn1.
Initially, the values of the two variables are: ...