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

Week 7 Coding Lab: Trail Helpers for a Hiking Club

Introduction to Computer Science Free sample edition

Part 1 — The Big Picture

This week you learned that a function is defined once with def and runs only when it is called, that arguments bind to parameters by position, that return hands a value back while print only shows it, that a function with no return hands back None, and that a local name lives in its call's frame and vanishes when the call ends. In this lab you put those ideas to work for an illustrative weekend hiking club. You predict what six short programs print, run them, and study every gap between your prediction and the run. Then you read three broken functions, one for each of the three function bugs, fix each with the smallest change that works, write a short function of your own, and check a chatbot's answers to the same questions 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 hiking club's helper functions, which of these six predictions about what a call hands back will you get wrong, and how will each run show you the difference between printing a value and returning it?

Workshop data: Trail helpers: six short programs and three broken functions

Source: Six short Python programs and three broken functions about an illustrative weekend hiking club, written for this lab and printed in full in Part 4; the club, its trails, and its hikers 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 functions in the second table
  • Language: Python 3, run in a free browser runner; no file to download and nothing to install
  • Context: an illustrative hiking club with trail distances, snack packs, water refills, and climbs

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 printed, with four spaces in front of each function-body line and each loop-body line, press Run, and copy the output into the Actual output column. 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 character for character from the output panel; at least one is likely to differ from your prediction.
  3. Type each broken function 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 thing.
  4. Fix each broken function 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 pace, the cost, or the elevation gain its description asks for.
  5. Paste the program from row 6 of the first table into Python Tutor, click the button to visualize it, and step forward one line at a time. Count how many times a frame named climb appears and then disappears. 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: Python Tutor shows a climb frame open beside the global names on every pass of the loop, holding its own meters, and vanish when the call returns.
  6. Write your own short function: one that takes a number of hours and returns that many hours in minutes, then call it with 2 inside print. Predict its output, run it, 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 output side by side.
  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 what each call hands back.

Student scaffold table 1
Program Your prediction Actual output from the run Same or different?
def trail_left(total_km, walked_km): with return total_km - walked_km, then print(trail_left(14, 9))
The same trail_left function, then print(trail_left(9, 14))
def snack_packs(hikers): with print(hikers * 2), then print(snack_packs(3))
water = 10, then def refill(): with water = 25 and print("in camp", water), then refill() and print("at trailhead", water)
def greet_hiker(): with print("Welcome!"), then print("Roll call"), then greet_hiker() twice
def climb(meters): with return meters * 3, then for leg in range(1, 4): with print(leg, climb(leg))

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

Student scaffold table 2
Broken function 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 12 for a 60-minute hike over 5 km: def pace(minutes, km): with the body per_km = minutes // km, then print(pace(60, 5))
Bug 2, should print 30, the cost of snacks for 5 hikers at 4 each plus a 10 trail fee: def total_cost(people): with print(people * 4), then cost = total_cost(5) and print(cost + 10)
Bug 3, should print 450, the climb from 300 to 750 meters: def elevation_gain(start, top): with gain = top - start and return gain, then elevation_gain(300, 750) and print(gain)

Write your own small function, then let the run confirm or correct what you expected it to print.

Student scaffold table 3
Line you wrote Output you expected Output of the run
Line 1
Line 2
Line 3
Line 4

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 and name the rule that explains the gap, such as arguments binding by position, a printing function handing back None, or an assignment inside a function making a local.
  2. For row 6 of the first table, how many lines printed, and how many times did a frame named climb appear and disappear in Python Tutor in step 5? Explain what that tells you about when a local name such as meters exists.
  3. Bug 1 runs without any error message but prints the wrong thing, while Bugs 2 and 3 stop with an error. Explain why Bug 1 is a logic error, and name the error type each of the other two 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 function hands back, using one claim from your critique as the example; or (b) describe how predicting before running changed what you noticed about print and return in this lab, using one row of your first table as the example.
  5. Every program in this lab called its functions with whole numbers that keep each trail distance positive or zero. Name one thing these runs could not tell you about a function that must handle any input, and say how you would check it 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 helper functions for a weekend hiking club, written for a class activity. Please do seven things, and keep each answer short. First, predict exactly what this program prints: def snack_packs(hikers): with print(hikers * 2) as its body, then print(snack_packs(3)). Second, predict what print(trail_left(9, 14)) prints for def trail_left(total_km, walked_km): with return total_km - walked_km, and explain in one sentence how the function gets that number. Third, write a loop that prints each leg number from 1 to 3 beside climb(leg), where def climb(meters): returns meters * 3. Fourth, this function should print 12 for print(pace(60, 5)) but prints None; fix it: def pace(minutes, km): with the body per_km = minutes // km. Fifth, this program stops with a NameError; fix it so it prints 450: def elevation_gain(start, top): with gain = top - start and return gain, then elevation_gain(300, 750) and print(gain). Sixth, does Python automatically hand back the last value a function computes, even with no return line? Seventh, for def status(km_left): with if km_left > 0: and return "keep hiking", what does print(status(0)) print?

Test the response for these likely failures:

  • Chatbots often predict that print(snack_packs(3)) prints only 6, treating the printing function as if it handed back the number it printed.
  • A chatbot may quote the right output, -5, for trail_left(9, 14) while explaining that the function subtracts the smaller number from the larger one, which would give 5.
  • Asked for legs 1 to 3, a chatbot may write for leg in range(1, 3):, which calls climb for only two legs.
  • A chatbot may fix the pace function by writing return minutes / km, which runs but changes what the function hands back.
  • A chatbot may fix the NameError by moving print(gain) inside the function, below the return gain line, and call the program working without running it.
  • A chatbot may claim that Python automatically hands back the last value a function computes, as some other languages do.
  • A chatbot may say print(status(0)) prints nothing, or prints keep hiking, missing that no return line runs when km_left is 0.

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: “print(snack_packs(3)) prints 6, because the function returns the number it prints. print(trail_left(9, 14)) prints -5 because the function subtracts the smaller distance from the larger one. To print legs 1 to 3, write for leg in range(1, 3):. To fix pace, write return minutes / km; it now prints the same pace as before. To fix the NameError, put print(gain) inside the function after return gain; this version is working. Python automatically hands back the last value a function computes, so a return line is optional. print(status(0)) prints nothing, because the if test is False.” 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 predicting what a function call hands back, matching arguments to parameters by position, telling return from print, reasoning about local and global names, and checking every claim about code by running it (Objective 5 and Objective 4), 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 hours-to-minutes function with its 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 hiking club: four completed tables (six predictions beside their runs, three broken functions read and fixed, your own hours-to-minutes function, 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 character for character, including any second line such as None. The table is mostly complete, but an actual output is missing 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 step by step to the actual output, with the governing rule named, such as positional binding, a printing function handing back None, or an inside assignment making a local. The gaps are listed, but a 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 1 identified as a logic error whose fix keeps floor division, and Bugs 2 and 3 named by their error types. 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 function The hours-to-minutes function runs without an error, hands its value back with return rather than printing it inside the body, and its expected and actual outputs are recorded side by side. The function runs but misses one requirement, such as printing inside the body instead of returning, or the expected or actual output is not recorded. No function 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 something these runs cannot show and a sensible way to check it. 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