Week 14 — Quiz (auto-graded) · Recursion (Intro)
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective tested: Objective 8 — base/recursive case, the call stack, and recursion vs. iteration.
Points: 10 (1 each) · Assignment group: Quizzes (10% of grade) · Due: end of Module 14.
Human-readable quiz with its vetted answer key. Import-ready Classic QTI in
F-quiz-week-14-qti.xml(parses with 10 items, one correct per single-answer item). Execution gate: PASS — every keyed output/result was produced by running the code.
Questions, key, and feedback
Q1 (MC). Every recursive function needs a recursive case (it calls itself on a smaller input). What is the OTHER required part — the simple case that stops the recursion?
- A. the loop case
- B. the base case ✅
- C. the return case
- D. the stack case
Feedback: The base case is the simplest input the function answers directly, with no further recursion — it's what stops the recursion.
Q2 (MC). What does this print?
def f(n):
if n == 0:
return 1
return n * f(n - 1)
print(f(5))
- A.
5 - B.
15 - C.
120✅ - D.
25
Feedback: This is factorial: 5×4×3×2×1 = 120. (Run-verified.)
Q3 (MC). What does this print?
def countdown(n):
if n == 0:
print('Go!')
return
print(n)
countdown(n - 1)
countdown(3)
- A.
Go! 3 2 1 - B.
3 2 1 Go!(on four lines) ✅ - C.
1 2 3 Go! - D.
3 2 1 0
Feedback: It prints on the way down (3, 2, 1) and reaches the base case (Go!) last. (Run-verified: 3, 2, 1, Go!)
Q4 (MC). What happens if a recursive function has no base case?
def bad(n):
return n + bad(n - 1)
print(bad(5))
- A. it returns 0
- B. it runs exactly once
- C. it recurses until Python raises a RecursionError ✅
- D. it prints 5
Feedback: With nothing to stop it, the call stack grows until Python cuts it off. (Run-verified:RecursionError: maximum recursion depth exceeded.)
Q5 (MC). What does this print?
def sum_to(n):
if n == 0:
return 0
return n + sum_to(n - 1)
print(sum_to(5))
- A.
5 - B.
10 - C.
15✅ - D.
120
Feedback: It adds 5+4+3+2+1 as the stack unwinds = 15. (Run-verified.)
Q6 (Multiple answer — select all that apply). Which statements about recursion are true?
- A. Every recursive function needs a base case ✅
- B. The recursive call must move toward the base case (a smaller input) ✅
- C. A recursive function can never be rewritten as a loop
- D. Anything done with recursion can also be done with iteration ✅
- E. A missing base case causes a RecursionError ✅
Feedback: A, B, D, E are all true. C is false — recursion and iteration are interchangeable in power (factorial works both ways).
Q7 (Matching). Match each term to its meaning.
| Term | Meaning |
|---|---|
| Base case | The simple input that stops the recursion |
| Recursive case | The part that calls the function on a smaller input |
| Call stack | The pile of waiting function calls |
| RecursionError | What happens with no reachable base case |
Feedback: The base case stops it; the recursive case shrinks it; the call stack holds the waiting calls; a missing base case → RecursionError.
Q8 (True / False). "In countdown(3) above, the base case (printing 'Go!') is reached last, after 3, 2, and 1."
- True ✅
- False
Feedback: True. The function prints n then recurses, so 3, 2, 1 print first and the base case Go! prints last. (Run-verified.)
Q9 (MC). A recursive factorial returns 120 for factorial(5). What does an ITERATIVE factorial (a for-loop) return for the same input?
- A. a different number
- B. 120 — the same answer ✅
- C. an error (loops can't do factorials)
- D. 5
Feedback: Recursion and iteration are two styles for the same result — both give 120. (Run-verified.)
Q10 (MC). This recursion never stops and raises a RecursionError. What is the fix?
def count_down(n):
print(n)
count_down(n - 1)
- A. Change
print(n)toprint(n + 1) - B. Add a base case, e.g.
if n == 0: return, before the recursive call ✅ - C. Remove the recursive call entirely
- D. Nothing — RecursionError cannot be avoided
Feedback: Add a base case that returns without recursing (e.g.,if n == 0: return) so it stops. (Run-verified: with the base case it counts down and stops.)
Answer key (quick reference)
| Q | Answer | Q | Answer |
|---|---|---|---|
| 1 | B (base case) | 6 | A, B, D, E |
| 2 | C (120) | 7 | Base→stops / Recursive→smaller call / Stack→waiting calls / RecursionError→no base |
| 3 | B (3 2 1 Go!) | 8 | True |
| 4 | C (RecursionError) | 9 | B (120) |
| 5 | C (15) | 10 | B (add a base case) |
Quality gate (self-checked): each single-answer item has exactly one correct option; the multiple-answer item keys are exact; the matching item pairs one-to-one. Execution gate: PASS — every printed output (Q2 120; Q3 3/2/1/Go!; Q5 15; Q9 120), the RecursionError (Q4, Q10), and the base-case-last order (Q8) were produced by running the code in Python.
Canvas placement block
canvas_object = Quizzes::Quiz
title = "Week 14 Quiz — Recursion (Intro)"
assignment_group = "Quizzes"
points_possible = 10
grading_type = points
due_offset_days = 6
published = true
shuffle_answers = true
ai_permitted = false
provenance = "~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com"
F-quiz-week-14-qti.xml) ships inside the course's .imscc package — it lands in the Canvas gradebook on import.~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com