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

Week 6 Coding Lab: Dice Tables and Loop Counts at Game Night

Introduction to Computer Science Free sample edition

Part 1 — The Big Picture

This week you learned that a for loop makes one pass per item it is handed, that a range stops before its stop number, that an accumulator inside a for loop builds a total, that end and a bare print() decide where a row ends, and that a nested loop runs its whole inner loop on every outer pass. In this lab you put those ideas to work at a board-game night. 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, fix each with the smallest change that works, write a short loop 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: At game night, which of these six predictions about ranges and nested loops will you get wrong, and how will each run show you exactly where a range stops and how many times an inner loop runs?

Workshop data: A game-night dice table: six short programs and three broken ones

Source: Six short Python programs and three broken programs about an illustrative board-game night with a six-sided die, written for this lab and printed in full in Part 4; the game and its rounds 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 game night with one six-sided die and a table of two-dice totals

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 loop body line and eight in front of each inner-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 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; two of the three run without any error but print the wrong thing.
  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, grid, or faces its description asks for.
  5. Paste the two-dice program from row 5 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 the inner loop's print line runs before a changes from 1 to 2. 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 b running through all of its values while a stays at 1, and the output panel grows one line per inner pass.
  6. Write your own short program: a for loop that adds the numbers 1 to 10 into a total that starts at 0, then prints the total. Choose the range so that 10 is included. 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 where a range stops and how often a loop runs.

Student scaffold table 1
Program Your prediction Actual output from the run Same or different?
for face in range(1, 7): print(face, end=" "), then print()
print(list(range(2, 13, 2)))
for ch in "ROLL": print(ch)
total = 0, then for face in range(1, 7): total += face, then print(total)
for a in range(1, 3): around for b in range(1, 4): print(a, b)
for a in range(1, 4): around for b in range(1, 4): print(a + b, end=" "), with a bare print() after the inner loop

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 the total of the faces 1 to 6: total = 0, then for face in range(1, 6): total += face, then print(total)
Bug 2, should print a 3 by 3 grid of dots on three rows: for row in range(3): around for col in range(3): print(".", end=""), with print() written after both loops and not indented
Bug 3, should print the faces 1 to 6, one per line, for a die whose number of sides was typed in: sides = "6", then for face in range(sides): print(face)

Write your own small loop, 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 the stop never being produced or the inner loop restarting on every outer pass.
  2. For row 5 of the first table, how many lines printed, and how does that count come from the number of outer passes and inner passes? Use what you saw in Python Tutor in step 5 as your evidence.
  3. Bug 1 and Bug 2 run without any error message but print the wrong thing. Explain why that makes each a logic error, and explain why Bug 3 is a runtime error instead.
  4. Choose one: (a) describe how you would decide whether to trust a chatbot's claim about which numbers a range produces, using one claim from your critique as the example; or (b) describe how predicting before running changed what you noticed about where a range stops in this lab, using one row of your first table as the example.
  5. Every program in this lab used a die with exactly six faces. Name one thing these runs could not tell you about a loop that must work for a die with any number of sides, 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 a board-game night, written for a class activity. Please do seven things, and keep each answer short. First, predict exactly what each of these programs prints: for face in range(1, 7): print(face, end=" ") followed by print(); print(list(range(2, 13, 2))); and total = 0, then for face in range(1, 7): total += face, then print(total), and explain in one sentence why that total comes out as it does. Second, write a loop that prints the faces of a six-sided die, 1 to 6, one per line. Third, this program should total the faces 1 to 6 but prints the wrong number; fix it: total = 0, then for face in range(1, 6): total += face, then print(total). Fourth, this program should print a 3 by 3 grid of dots on three rows but prints one long row; fix it: for row in range(3): around for col in range(3): print(".", end=""), with print() written after both loops, not indented. Fifth, this program stops with an error; name the error type and fix it so it prints 1 to 6, one per line: sides = "6", then for face in range(sides): print(face). Sixth, can range() take a step of 0.5, as in list(range(0, 3, 0.5))? Seventh, with n = 0, what does for i in range(n): print("*", end="") followed by print() print?

Test the response for these likely failures:

  • Chatbots often predict that print(list(range(2, 13, 2))) ends with 13 or 14, treating the stop as a number the range reaches.
  • Asked for the faces 1 to 6, a chatbot may write for face in range(1, 6):, reading the second number as the last face.
  • A chatbot may quote the correct total 21 for the loop over range(1, 7) while explaining that it adds 1 through 7, which would give 28.
  • A chatbot may fix the TypeError program by writing for face in range(int(sides)):, which runs without an error but prints 0 to 5 instead of 1 to 6.
  • A chatbot may fix the dot grid by moving the bare print() inside the inner loop and call it working without running it.
  • A chatbot may say range() accepts a step of 0.5 and list the values it would produce.
  • A chatbot may say that with n = 0 the star loop prints one star, or that range(0) raises an error.

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(list(range(2, 13, 2))) prints [2, 4, 6, 8, 10, 12, 13], because the range runs up to 13. To print the faces 1 to 6, write for face in range(1, 6):. The total over range(1, 7) is 21 because it adds 1 through 7. To fix the TypeError program, write for face in range(int(sides)):; it now prints the faces 1 to 6. To fix the dot grid, put print() inside the inner loop; this version is working. range() accepts a step of 0.5, so list(range(0, 3, 0.5)) gives six values. With n = 0, the star loop prints one star.” 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 which numbers a range produces, totalling with a for loop, tracing a nested loop, walking a string, and checking every claim about code by running it (Objective 4 and Objective 2), 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 total-of-1-to-10 program 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 game night: four completed tables (six predictions beside their runs, three broken programs read and fixed, your own total-of-1-to-10 loop, 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 exclusive stop, a range starting at 0, or the inner loop restarting on every outer pass. 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 Bugs 1 and 2 identified as logic errors and Bug 3's fix printing 1 to 6 rather than 0 to 5. 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 total-of-1-to-10 loop runs without an error, uses a range that includes 10, keeps a total that starts at 0, and its expected and actual outputs are recorded side by side. The program runs but misses one requirement, such as a range that stops before 10, or the expected or actual output is not recorded. 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 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