← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 14 · Coding Lab

Week 14 Coding Lab: A Community Garden That Calls Itself

Introduction to Computer Science Free sample edition

Part 1 — The Big Picture

This week you learned that a recursive function calls itself on a smaller input, that it needs a base case that answers at once and a recursive case that moves toward it, that the calls pile up on the call stack and unwind in reverse order, and that a recursion and a loop can give the same answer. In this lab you put those ideas to work on the programs of an illustrative community garden. You predict what six short recursive programs print, run them, and study every gap between your prediction and the run. Then you read three broken programs, fix each with the smallest change that works, write a short recursive program of your own and a loop that checks it, and test a chatbot's answers about the same programs by running the code, because a chatbot predicts likely text and does not run your program.

Time budget: Plan for about 90 minutes.

Part 2 — The Task

Guiding question: For the garden's recursive programs, which of these six predictions about the order of the printed lines, the number of calls, or the value handed back will you get wrong, and how will each run show you where the recursion stops?

Workshop data: Garden programs: six short recursive programs and three broken programs

Source: Six short Python programs and three broken programs about an illustrative community garden's watering rounds, harvest baskets, and seedlings, written for this lab and described in full in Part 4; the garden and its beds are invented and describe no real group or person.

  • Rows: 9 short programs in all: 6 programs to trace in the first table and 3 broken programs in the second table
  • Language: Python 3, run in a free browser runner; no file to download and nothing to install
  • Context: an illustrative community garden with watering rounds, baskets of vegetables, and doubling seedlings

Part 3 — Materials & Procedure

Tools and materials

  • A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting

Ways of working

  • write-run-and-verify
  • trace-and-predict-output
  • find-and-fix-the-bug

Procedure

  1. Open a free browser Python runner in one tab and Python Tutor at pythontutor.com in another. In the runner, delete any sample code so the editor is blank. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: An empty editor with a Run button and a separate output panel.
  2. In the first table in Part 4, write your prediction for each of the six programs before you run anything. Then type each program into the runner exactly as described, with four spaces in front of every line inside a def or an if, press Run, and copy the output into the Actual output column, one line at a time. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: Six actual outputs, one per row, each copied line for line from the output panel; at least one is likely to differ from your prediction.
  3. Type each broken program from the second table into the runner and press Run. For an error, scroll to the bottom of the error message and copy the error type from its last line. For a program that runs, compare what it printed with what its description says it should print. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: The second table shows what each broken program printed, or the error type on its last line; one of the three runs without any error but prints the wrong value.
  4. Fix each broken program with the smallest change that makes it do what its description in Part 4 says, run the fixed version, and record the new output. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: Each fixed program runs without an error and prints the total, the count, or the seedlings its description asks for.
  5. Paste the harvest program from the third row of the first table into Python Tutor, click the button to visualize it, and step forward one line at a time. Count the frames as they appear, and watch each one disappear as its call returns. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: A new frame appears for each call, each holding its own shorter list, and the frames disappear from the newest to the oldest as the values come back.
  6. Write your own short recursive program: a function named packets that returns 0 for an empty list and otherwise adds the first seed count to the total of the rest, called on the list 12, 5, 9, plus a for loop that adds the same list. Predict both outputs, run the program, and fill in the third table. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: A short program that runs without an error, with your predicted and actual outputs side by side and the recursive and loop totals compared.
  7. Open your approved chatbot, paste the critique prompt from Part 6 as one message, then check each of its claims by running the code it talks about. If you are using the equivalent route, mark up the printed flawed analysis in the same way. Tool: A free browser-based Python runner (an online editor that runs Python 3 with no account and nothing to install), Python Tutor at pythontutor.com for step-by-step visualization, the official Python documentation at docs.python.org, and one approved chatbot used as a pair-programmer whose code the student runs before trusting. Check: The fourth table lists each chatbot claim, what your run showed, and a correction wherever the two disagree.

Fallback route

When to use it: Use this route if your browser Python runner will not open or will not run code.

Run every program in Python Tutor instead, which also runs Python 3 in the browser: paste each program, click the button to visualize it, and step to the end to read its output or its error. Complete every table, analysis question, and the critique step, and submit the same items for equal credit.

This route earns the same credit as the primary route.

Part 4 — The Scaffold

Predict first and run second, so the gap between the two columns is your own evidence of where each recursion stops and what it hands back.

Student scaffold table 1
Program Your prediction Actual output from the run Same or different?
water(2), where water(n) prints done and returns when n is 0, and otherwise prints "bed", n and then calls water(n - 1)
refill(2), the same as water except that print("bed", n) comes after the recursive call
print(harvest([4, 7, 2])), where harvest returns 0 for [] and otherwise returns baskets[0] + harvest(baskets[1:])
print(seeds(3)), where seeds returns 1 when n is 0 and otherwise returns 2 * seeds(n - 1)
print(tally(4)), where tally returns 0 when n is 0 and otherwise returns n + tally(n - 1), then a loop that adds i for i in range(1, 5) and prints its total
x = water(1), then print(x)

Read each broken program from its run before you change a single character.

Student scaffold table 2
Broken program and what it should do What printed, or the error type on the last line Your one-change fix Output after the fix
Bug 1, should print 13, the baskets' total: harvest with only the line return baskets[0] + harvest(baskets[1:]), then print(harvest([4, 7, 2]))
Bug 2, should print 10, the beds watered so far: tally with the base case for 0 but the recursive call n + tally(n), then print(tally(4))
Bug 3, should print 8, the seedlings after three doublings: seeds with the base case return 0 instead of return 1, then print(seeds(3))

Write your own small recursive program and a loop, then let the run confirm or correct what you expected each to print.

Student scaffold table 3
Line you wrote Output you expected Output of the run
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8

Check every chatbot claim against a run so the run, not the chatbot, has the last word.

Student scaffold table 4
Chatbot claim, quoted What your run showed Correct as stated, or your correction

Part 5 — Analysis Questions

  1. Which of your six predictions in the first table differed from the run? For each one, write the step-by-step trace that reaches the actual output, one line per call, and name the rule that explains the gap, such as lines after a recursive call running on the way back, the base case answering at once, or a function that only prints handing back None.
  2. In step 5, how many frames did Python Tutor show at the deepest moment of the harvest program, and what list did each frame hold? Explain what that tells you about why each call keeps its own input.
  3. Bug 3 runs without any error message but prints the wrong value, while Bugs 1 and 2 stop with errors. Explain why Bug 3 is a logic error, and name the error type each of Bugs 1 and 2 raised and why the program raised it.
  4. Choose one: (a) describe how you would decide whether to trust a chatbot's claim about what a recursive function prints, using one claim from your critique as the example; or (b) describe how predicting before running changed what you noticed about the order of printed lines in this lab, using one row of your first table as the example.
  5. Your packets program was tested on one list of three numbers. Name one input it was never tested on, such as an empty list or a much longer list, and say how you would check what it does by running more cases.

Part 6 — AI-Critique Moment

Choose one equal-credit critique route. Route A: ask an approved AI tool to critique your completed work, then check its response against your own evidence. Route B is the no-AI equivalent printed below.

Approved tools: Claude, Gemini, ChatGPT, Grok, Microsoft Copilot.

Prompt to paste:

I'm doing a beginner Python lab about recursion, using an illustrative community garden's watering and harvest programs written for a class activity. Please do seven things, and keep each answer short. First, predict exactly what this prints: def refill(n): with if n == 0: then print("done") and return, then refill(n - 1) followed by print("bed", n), and finally refill(2). Second, harvest(baskets) returns 0 for an empty list and otherwise returns baskets[0] + harvest(baskets[1:]); say what harvest([4, 7, 2]) prints and how many calls it makes. Third, write a for loop that adds the same numbers as tally(4), where tally(n) returns n + tally(n - 1) and returns 0 when n is 0. Fourth, Bug 1 is harvest with no base case and stops with an error; fix it. Fifth, Bug 2 is tally with the recursive call tally(n) and stops with an error; fix it. Sixth, what does Python do when a recursive function with no base case runs out of items? Seventh, does the repaired tally work for every whole number you could pass it?

Test the response for these likely failures:

  • Chatbots often read the name and the shape of refill(2), expect a countdown, and predict that it prints bed 2, then bed 1, then done.
  • A chatbot may report the right total, 13, for harvest([4, 7, 2]) and then explain that the function makes three calls, one per basket.
  • Asked for a loop version of tally(4), a chatbot may write for i in range(1, 4): and say it adds 1 through 4.
  • A chatbot may fix the IndexError in Bug 1 by adding if len(baskets) == 1: return 0, which runs without an error but changes what the function adds.
  • A chatbot may fix Bug 2 by changing the recursive call to tally(n + 1) and call the program working without running it.
  • A chatbot may claim that Python quietly returns 0 when a recursive function with no base case runs out of items, so Bug 1 only needs a print to show the total.
  • A chatbot may say the repaired tally works for any whole number, missing a negative input such as tally(-1).

Write 2-3 sentences that name one thing the chatbot got right and at least one claim you corrected, and for each correction give the output or error type your own run showed.

Equivalent route (no AI required)

No AI account is required for this lab. Instead of the chatbot, critique this flawed analysis, printed here in full: “refill(2) prints bed 2, then bed 1, then done, because it counts down from 2. harvest([4, 7, 2]) prints 13 after three calls, one per basket. A loop that matches tally(4) is for i in range(1, 4):, adding to a total that starts at 0. To fix Bug 1, add if len(baskets) == 1: return 0; the function now runs without an error. To fix Bug 2, change the call to tally(n + 1); this version is working. When a recursive function with no base case runs out of items, Python returns 0 for you, so Bug 1 only needs a print. The repaired tally works for any whole number.” Mark it up: quote each flawed sentence, run the code it describes in your browser Python runner, and write the corrected claim beside it with the run's output or error type as evidence. This route assesses the same objectives as the chatbot critique, namely tracing a recursive function call by call, naming its base case and recursive case, comparing recursion with a loop, and checking every claim about a recursion by running it (Objective 8 and Objective 5), and it takes comparable effort, about 20 minutes of the lab. It is scored by the same rubric for the same credit, and its marked-up analysis replaces the chatbot report and share link in your submission. You do not need to say which route you chose.

Part 7 — What to Submit

  • All four completed scaffold tables
  • Written answers to all five analysis questions
  • Your packets program and its loop check with their run output
  • The chatbot critique report with its share link, or the equivalent route's marked-up flawed analysis

Deliverable:

A short Coding Lab report on an illustrative community garden's recursive programs: four completed tables (six predictions beside their runs, three broken programs read and fixed, your own packets program with its loop check, and the checked chatbot claims), written answers to five analysis questions, and a critique of a chatbot's answers to the same questions, or, on the equivalent route, a marked-up correction of the printed flawed analysis. Submit in any accessible file type or as a link; a recorded response may be submitted as audio or video with a transcript, or as text. Choose a written, recorded, or visual form for your answers, such as screen captures of your runs with a short note for each; every form is graded by the same rubric.

Rubric

The rubric below shows how each submitted part is evaluated; bands are full, partial, or none.

Workshop evaluation criteria
Criterion Full Partial None
Predicting and running the six programs All six predictions are recorded before the runs, and all six actual outputs match what the programs print, copied line for line and in the order the lines appeared. The table is mostly complete, but an actual output is missing, out of order, or miscopied, or predictions appear to have been filled in after running. No predictions or runs are recorded, or the outputs are invented rather than run.
Explaining the gaps between prediction and run Every prediction that differed from its run is traced call by call to the actual output, with the governing rule named, such as lines after a recursive call running as the frames unwind, or a printing function handing back None. The gaps are listed, but a call-by-call trace is missing or the rule behind a gap is not named. No gap is explained, or the response blames the runner instead of the rule.
Finding and fixing the three bugs Each bug is read correctly from its run: what printed or the error type, a one-change fix, and the fixed program's output, with Bug 3 identified as a logic error and Bugs 1 and 2 named by their error types, and each fix keeping every basket, bed, or doubling the description asks for. Two of the three bugs are read and fixed correctly, or all three are fixed but an error type or the run evidence is missing. The bugs are not attempted, or errors are named without running the programs.
Writing, running, and verifying a program The packets program runs without an error, has a base case on the empty list and a recursive case on a shorter list, and its loop check is run, with expected and actual outputs recorded side by side. The program runs but misses one requirement, such as a missing loop check or an unrecorded expected or actual output. No program is submitted, or it was not run.
Critiquing the AI analysis or the printed flawed analysis The chatbot's answers, or on the equivalent route the printed flawed analysis, are quoted and at least two claims are corrected with evidence from the student's own runs. The critique names errors but corrects only one, or corrects without run evidence, on either route. No critique is submitted on either route, or chatbot or flawed text is pasted without any checking.
Reflection and limitation The chosen reflection option is answered with a specific example from this lab, and the limitation answer names an untested input and a sensible way to check it by running more cases. The reflection or the limitation is general, without an example from this lab or a way to check it. The reflection and limitation questions are not answered.

Quality Gate

  • Every prediction in the first table was written before its program was run.
  • Every actual output and error type is copied from your own run, never from memory or a chatbot.
  • Each error is named by its type from the last line of the error message, not by the wording after the colon.
  • Each fix changes as little as possible and its fixed program was run.
  • No output, count, or claim is invented anywhere in the submission.
  • The critique quotes the chatbot or the flawed analysis and corrects at least two claims with evidence from your runs.

Built with The Course Maker · samples.thecoursemaker.com