Solution Review: Fibonacci Series
Review the solution for the "Fibonacci Series" problem.
We'll cover the following...
Solution
Let’s explore the solution to the problem of the Fibonacci series.
Press + to interact
def fib(n):# The first and second values will always be fixedfirst = 0second = 1if n < 1:return -1if n == 1:return firstif n == 2:return secondcount = 3 # Starting from 3 because we already know the first two valueswhile count <= n:fib_n = first + secondfirst = secondsecond = fib_ncount += 1 # Increment count in each iterationreturn fib_nn = 7print(fib(n))
...
Access this course and 1400+ top-rated courses and projects.