0
Fib function
I can't understand really what happens : def fib(n): if n is 0 or n is 1: return 1 else: return fib(n-1) + fib(n-2)
2 Answers
+ 3
Fibonacci numbers:
The first Fibonacci number is 0, the second is 1, the third is 0 + 1 = 1(i.e the third Fibonacci is the sum of the first and second fibonnaci). Likewise the fourth fibonnaci is 1(second fibonnaci) + 1(third fibonnaci) = 2.
From this u see that a fibonnaci number is equal to the sum of the two fibonnaci numbers before it, so fib(n) = fib(n-1) + fib(n-2) and fib(0) = 0 , fib(1) = 1