Loading...
Loading...
Loading...
A growth model starts with 0 and 1, and every next value is the sum of the two before it: 0, 1, 1, 2, 3, 5, ... Write a recursive function fib(n) and print the n-th value, counting the first as number 0.
Example
Input
10
Output
55
The sequence reaches 55 at position 10.
Try the problem first. Open one hint at a time.
There are two base cases: fib(0) is 0 and fib(1) is 1.
For larger n, add fib(n - 1) and fib(n - 2).
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor