December 2023
Intermediate to advanced
504 pages
11h 43m
English
The Fibonacci sequence is a mathematical sequence of numbers that goes like this until infinity:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…
This sequence begins with the numbers 0 and 1, and each subsequent number is the sum of the previous two numbers of the sequence. For example, the number 55 was computed because it is the sum of the previous two numbers, which are 21 and 34.
The following Python function returns the Nth number in the Fibonacci sequence. For example, if we pass the number 10 to the function, it will return 55, as 55 is the tenth number in the series. (The 0 is considered the 0th number in the series.)
| | def fib(n): |
| | if n == 0 or n == 1: |
| | return n |
| | |
| | return fib(n - 2) + fib(n - 1) |
The key line ...
Read now
Unlock full access