Kodewick
Start learning →
Starter←→0 / 80

Rocket countdown

#063StarterRecursionLists3 min

Before launch, the rocket counts down. Write countdown(n) to return [n, n-1, …, 1], or an empty list when n is 0. No loop this time: let the function call itself, since countdown(n - 1) is the rest of the list.

Examples
countdown(3)→[3, 2, 1]
countdown(0)→[]
main.py
def countdown(n):
    if n == 0:
        return []
    # your code here: n first, then countdown(n - 1) (instead of return [])
    return []
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.