Challenge 3: Corresponding Fibonacci Number
Given an index, find the corresponding Fibonacci number.
Problem Statement
Implement a function that takes a variable testVariable
and finds the number that is placed at that index in the Fibonacci sequence.
What is the Fibonacci Sequence?
The Fibonacci sequence is one of the most famous formulas in mathematics. Each number in the sequence is the sum of the two numbers that precede it.
So, the sequence goes:
Indexing starts at . Therefore, at index we have the element , at index we have the element , at index we have the element , and so on.
Generic Mathematical Notation of Fibonacci Sequence
Any number, at index in the series, can be calculated using the following equation:
n n-2n-1
By default, the first and the second number in the sequence are and
0
1
2 01
3 12
4 23
5 34
6 45
7 56
Below is a visualization for the computation of the first elements in the Fibonacci sequence:
Input
A testVariable
containing the index whose corresponding element in the Fibonacci sequence needs to be found.
Output
The corresponding element in the Fibonacci sequence.
Sample Input
7
Sample Output
13
Try it Yourself
Try to attempt this challenge by yourself before moving on to the solution. Good luck!
def fibonacci(testVariable) :# Write your code herereturn None
In the next lesson, we have the solution review of this problem.