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

Week 4 Coding Lab: Branches at an Amusement-Park Ride Gate

Introduction to Computer Science Free sample edition

Part 1 — The Big Picture

This week you learned that a comparison asks a yes-or-no question and gives True or False, that and, or, and not combine those answers in the order not, then and, then or, and that an if, elif, and else chain runs only its first true branch. In this lab you put those ideas to work at an amusement-park ride gate. You predict what six short programs print, run them, and study every gap between your prediction and the run. Then you read three broken programs, name the family each bug belongs to, fix each with the smallest change that works, write a short chain 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: When a 118 cm rider who is 9 years old arrives with an adult, which of these six predictions will you get wrong, and how will each run show you the order in which Python checked the conditions?

Workshop data: An amusement-park ride gate: six short programs and three broken ones

Source: Six short Python programs and three broken programs about an illustrative amusement-park ride gate, written for this lab and printed in full in Part 4; the heights, ages, and ride rules are invented and describe no real park 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 ride gate that checks a rider's height in centimetres, age, and whether an adult is along

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, including its setup lines height = 118, with_adult = True, and age = 9, 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 program from the second table into the runner with four spaces of indentation under each if, elif, and else line, 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; two of the three run without any error message but print the wrong thing.
  4. Name the family of each bug (a syntax error or a logic error), fix it with the smallest change that makes it do what its description in Part 4 says, run the fixed version, and record the new output. For the third bug, run the fixed program twice, once with height = 119 and once with height = 120. 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 message its description asks for, and the third bug's fix prints a different message for 119 than for 120.
  5. Paste the sixth program from the first table, with its setup lines, into Python Tutor, click the button to visualize it, and step forward one line at a time. Watch which if or elif line the arrow checks and which block it skips. 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 the arrow checking both tests and then jumping to the else block, which matches what the runner printed.
  6. Write your own chain for a ticket booth: set age = 9, then write an if, elif, and else chain that prints Senior ticket for an age of 65 or more, Adult ticket for an age of 13 or more, and Child ticket otherwise. Predict its output, run it, then change age to 13 and to 65 and run it again each time, 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 chain that runs without an error, with your predicted and actual output side by side for each of the three ages.
  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 with its setup lines, 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 the order in which Python checks a condition.

Student scaffold table 1
Program (setup: height = 118, with_adult = True, and age = 9) Your prediction Actual output from the run Same or different?
print(height >= 120)
print(height >= 120 or with_adult)
print(not with_adult and height >= 110)
print(height == 118, height != 118)
print(with_adult or height >= 140 and age > 12)
A chain that prints All rides when height >= 140, Most rides in an elif when height >= 120, and Family rides in the else

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 Bug family and your one-change fix Output after the fix
Bug 1, should print Exactly 118 when height = 118: the line if height = 118: followed by an indented print("Exactly 118")
Bug 2, should print All rides when height = 145: if height >= 120: with an indented print("Most rides"), then elif height >= 140: with an indented print("All rides")
Bug 3, should print May ride for a rider 120 cm or taller, tested with height = 120: if height > 120: with an indented print("May ride"), then else: with an indented print("Too short")

Write your own small chain, then let three runs confirm or correct what you expected it to print.

Student scaffold table 3
Age you set Output you expected Output of the run
age = 9
age = 13
age = 65

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 the priority not, then and, then or, or only the first true branch running.
  2. Bug 1 printed nothing at all, not even from its first line, while Bug 2 and Bug 3 ran to the end. What did each last line or output show, and why does that make Bug 1 a syntax error and the other two logic errors?
  3. Bug 3 printed Too short for a 120 cm rider. Explain why the comparison > leaves out the value 120 while >= keeps it, and why testing 119 and 120 together is a better check of your fix than testing 150 alone.
  4. Choose one: (a) describe how you would decide whether to trust a chatbot's claim about which branch of a chain runs, using one claim from your critique as the example; or (b) describe how predicting before running changed what you noticed about the order of the tests in this lab, using one row of your first table as the example.
  5. Every run in this lab used heights and ages written as whole numbers in the program. Name one thing these runs could not tell you about how the ride gate would behave with real riders, and say how you would check it.

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 an amusement-park ride gate, written for a class activity. Please do six things, and keep each answer short. First, with height = 118, with_adult = True, and age = 9, predict exactly what each of these lines prints, and explain your reasoning for the second and fifth: print(height >= 120); print(height >= 120 or with_adult); print(not with_adult and height >= 110); print(height == 118, height != 118); print(with_adult or height >= 140 and age > 12). Second, this program stops with an error before printing anything. Name the error type and fix it so it prints Exactly 118: height = 118 then if height = 118: then an indented print("Exactly 118"). Third, with height = 145 this chain prints Most rides but should print All rides. Fix it: if height >= 120: then an indented print("Most rides"), then elif height >= 140: then an indented print("All rides"). Fourth, the ride rule says riders 120 cm or taller may ride, but with height = 120 this program prints Too short. Fix it: if height > 120: then an indented print("May ride"), then else: then an indented print("Too short"). Fifth, can I write elseif instead of elif in Python, as some languages allow? Sixth, tell me which heights you would test to be sure your fix for the fourth program works.

Test the response for these likely failures:

  • Chatbots often read print(with_adult or height >= 140 and age > 12) from left to right, working out the or first, and predict False.
  • A chatbot may correctly say print(height >= 120 or with_adult) prints True but explain that the rider is at least 120 cm tall, which contradicts the first line printing False.
  • A chatbot may fix the error program by writing if height == "118": and call it working because it no longer raises an error.
  • A chatbot may fix the out-of-order chain by turning the elif into a second if, which runs without an error.
  • A chatbot may say height > 120 already lets a 120 cm rider through, or may move the line to height > 121.
  • A chatbot may say Python accepts elseif, or else if on one line, as another spelling of elif.
  • Asked which heights to test, a chatbot may suggest only a very tall and a very short rider, such as 150 and 100, and skip the edge of the rule.

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: “With height = 118, with_adult = True, and age = 9, print(with_adult or height >= 140 and age > 12) prints False, because Python works out the or first. print(height >= 120 or with_adult) prints True because the rider is at least 120 cm tall. To fix Bug 1, write if height == "118":; this version is correct because it no longer raises an error. To fix Bug 2, change its elif into a second if; then a 145 cm rider sees the right message. Bug 3 is already correct, because height > 120 lets a 120 cm rider through. Python also accepts elseif as another spelling of elif. To check the Bug 3 rule, test a 150 cm rider and a 100 cm rider.” 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, including runs of the Bug 3 program at 119 and at 120. This route assesses the same objectives as the chatbot critique, namely writing and reading conditions with comparison and logical operators, predicting which branch of an if, elif, and else chain runs, and checking every claim about code by running it (Objective 3 — write Boolean expressions with comparison and logical operators, read and build a truth table, and control which code runs with if, elif, and else), 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 ticket-booth chain with its runs for ages 9, 13, and 65
  • 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 amusement-park ride gate: four completed tables (six predictions beside their runs, three broken programs read, named, and fixed, your own ticket-booth chain run for three ages, 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. 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 the priority not, then and, then or, or only the first true branch running. 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, naming, and fixing the three bugs Each bug is read correctly from its run, named as a syntax error or a logic error, fixed with one change, and its fixed program's output is recorded, including runs of the third fix at 119 and at 120. Two of the three bugs are read and fixed correctly, or all three are fixed but a bug family, 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 chain The ticket-booth chain runs without an error, tests the stricter age first, and its expected and actual outputs for ages 9, 13, and 65 are recorded side by side. The chain runs but misses one requirement, such as a test order that sends 65 to the wrong ticket, or one of the three runs is not recorded. No chain 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 bug is named as a syntax error or a logic error, and each fix changes as little as possible and 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