Exam-style question
Try this first
Write a Python recursive function called countdown(n) that displays the values from n down to 1. State the base case and explain how the general case moves towards it.
Answer and explanation
Concise answer
```python def countdown(n): if n == 0: return print(n) countdown(n - 1) ``` The base case is `n == 0`, which stops the function without making another call.
Why this is correct
A complete answer needs a stopping condition and a recursive call. The recursive call must change n so that repeated calls eventually reach the base case. For example, countdown(3) displays 3, 2 and 1, then reaches countdown(0) and stops.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
