Search⌘ K

Solution Review: Return Sequence of Fibonacci Numbers

Understand how to generate Fibonacci sequences in Python by applying iterator logic that sums previous elements. This lesson helps you implement a custom iterator to return Fibonacci numbers, reinforcing your skills before advancing to Python generators.

We'll cover the following...

Solution:

The first and second elements of the Fibonacci sequence are 0 and 1 respectively. Each successive element is obtained by adding the two elements before it. For instance, the 3rd element is obtained by adding the 1st and 2nd elements, the 4th is obtained by adding the 2nd and 3rd elements, and so on. Thus we can conclude the following for myArray in a Fibonacci sequence:

myArray[i]=myArr ...