← All practice pages

Python

Python Recursion

A recursive function calls itself on a smaller version of the problem until it reaches a case simple enough to answer directly. That stopping case is what keeps it from running forever.

Try it now

Write a Python function called "fibonacci" that takes an integer n and returns a list of the first n Fibonacci numbers. The sequence starts with [0, 1]. For n=0 return an empty list, for n=1 return [0].

Create a free account to run your answer and get ARIA's review.