logo

AQA A-Level Computer Science practice

What is the result of this Python function call? ```python def f(n): if n == 0: return 0 return n + f(n - 1) f(3) ```

Try the question first, then check the answer and practise the same topic again.

At a glance

MCQ

Type

practice

Style

Topic

Programming

Exam-style question

Try this first

What is the result of this Python function call? ```python def f(n): if n == 0: return 0 return n + f(n - 1) f(3) ```.

  1. A.3
  2. B.5
  3. C.6
  4. D.9

Answer and explanation

Concise answer

6

Why this is correct

The calls produce 3 + f(2), then 2 + f(1), then 1 + f(0). The base case returns 0, giving 3 + 2 + 1 + 0 = 6.

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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions