Week 2 — Coding Lab / Programming Studio · "Boxes, Math & a Sneaky Decimal"
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective: Objective 2 — use variables, the four core types, and expressions; trace / vs // vs %; convert types and fix a type/assignment bug · SLO A (write & run) + SLO B (trace & debug)
Worth 50 points · Coding Labs group = 15% of the grade · Coding Lab 2
Format: a hands-on programming studio worked in a free online Python environment — you'll (a) write programs with variables, (b) trace an expression table and predict its output, and (c) find and fix a bug — and then catch the AI's mistake when it claims 10 / 2 is 5.
This is the course's signature weekly component. Every instructional week has one Coding Lab. Everything runs in your browser — nothing to buy or install. The whole habit of this lab (and this course): don't guess what code does — run it and read what Python actually prints.
Part 1 — The Big Picture
This week you gave programs a memory: variables hold values, and expressions do math with them. The catch is that the math has rules — operator precedence, and three different "divisions" (/, //, %) that give three different answers. This lab is the Week-1 loop again — write → trace → debug — now with variables and arithmetic. By the end you'll have built small programs with variables, predicted a tricky expression table (and seen / make a decimal), fixed a type bug, and watched a variable change step by step in Python Tutor.
Your tools (both free, both in the browser):
- An online Python editor to write and run code: 🔗 https://www.online-python.com/ (or 🔗 https://www.programiz.com/python-programming/online-compiler)
- Python Tutor to watch code run step by step: 🔗 https://pythontutor.com/ — paste a program, click Visualize Execution, then step forward. This week it shines: you'll literally see a box's value change.
Part 2 — Setup (2 minutes)
- Open the online Python editor in a new tab.
- Delete any sample code so you have a blank editor.
- Type these two lines and press Run:
python score = 10 print(score)
You should see10. You just stored a value in a variable and printed it. 🎉
Part 3 — (a) Write: Programs with Variables
Write each of these in the editor, run it, and paste your code and its output into your submission.
- Seconds → minutes. A video is 200 seconds long. Store that in a variable
total_seconds, then use//and%to compute and print the whole minutes on one line and the leftover seconds on the next. (Hint:total_seconds // 60andtotal_seconds % 60.) - Receipt total. Store a
subtotalof 20, compute a 7%tax(subtotal * 0.07), add them into atotal, and print the total. Run it and write down what it printed. (Notice what kind of number you get.) - Check the types. Make three variables — one
int, onefloat, onestr(your choice of values) — and print thetype()of each. Confirm Python reports<class 'int'>,<class 'float'>, and<class 'str'>.
Part 4 — (b) Trace: Predict, Then Run
For each program below, first write your predicted output in the table (don't run it yet!). Then run each one in the editor and fill in the "Actual" column. Where your prediction and the actual output differ, that's the lesson.
| # | Program | Your prediction | Actual (after running) |
|---|---|---|---|
| 1 | print(2 + 3 * 4) |
______ | ______ |
| 2 | print(10 / 2) |
______ | ______ |
| 3 | print(7 // 2) |
______ | ______ |
| 4 | print(7 % 2) |
______ | ______ |
| 5 | print(2 ** 3) |
______ | ______ |
| 6 | print(20 - 6 / 2) |
______ | ______ |
Hint for #2 and #6: look carefully at what kind of number Python prints when a
/is involved. It might surprise you.
Visualize a variable change: paste this program into Python Tutor and step through it with Visualize Execution. Watch the boxes a, b, and temp — see how the values swap:
a = 1
b = 2
temp = a
a = b
b = temp
print(a)
print(b)
Predict what it prints before you step through it, then confirm. (What do a and b hold at the very end?)
Part 5 — (c) Find & Fix the Bug
Each program below is broken or does the wrong thing. For each one: run it, figure out what went wrong, then write (i) what the problem is, (ii) why it happened, and (iii) the fixed program (and what it prints).
Bug A — the wrong total
quantity = "3"
price = 4
total = quantity * price
print(total)
(This one doesn't crash — but the output is wrong. Run it and look closely at what total becomes.)
Bug B — used too early
print(total)
total = 5 + 3
Part 6 — Analysis Questions
Answer in a sentence or two each:
1. In the trace table, which prediction did you get wrong (if any)? What did you learn from the gap?
2. Programs #2 (print(10 / 2)) and #3 (print(7 // 2)) both divide, but give different kinds of answers. What's the difference between / and //?
3. Program #4 (print(7 % 2)) gave 1. What does the % operator compute, and what's one real use for it?
4. In Bug A, the program printed something surprising instead of 12. Why did "3" * 4 behave that way, and what one change fixes it?
5. Connect it: Bug A is a type bug and Bug B is an order bug. In your own words, what's the difference — and how could type() have helped you spot Bug A faster?
Part 7 — AI-Critique Moment (required — this is the BYOAI step)
Now bring in your approved chatbot (Gemini, Claude, or ChatGPT) and be the programmer who checks its work.
- Paste this to the chatbot: "What will this Python program print?
print(10 / 2)and alsoprint(7 // 2)andprint(7 % 2). Give me the exact output of each." - Check every claim by running each program yourself in the editor:
- Did it sayprint(10 / 2)prints5— or the correct5.0? (Chatbots very often drop the.0and say5. Python prints5.0, because/always makes a float.)
- Did it get7 // 2as3(floor division) — or wrongly say3.5?
- Did it get7 % 2as1(the remainder) — or mix it up with//? - Write 2–3 sentences reporting what the AI got right and at least one thing you had to correct or verify carefully. If it happened to get everything right, say how you confirmed each one by running it — that's the skill.
The habit all term: the tool drafts, you run it and judge. This week's signature catch is the division one — a chatbot will confidently tell you
10 / 2is5. Catching that by running the code is the entire point of this course.
Part 8 — What to Submit
Submit a single document (or text entry) with: your Part 3 programs and their outputs; your completed Part 4 trace table (both columns) plus your Python Tutor swap prediction; your Part 5 bug answers (problem, why, and the fix for each); your Part 6 answers; and your Part 7 AI-critique paragraph. Due Sunday, Sep 13, 11:59 p.m. (50 points).
Instructor answer key & model outputs — REMOVE BEFORE PUBLISHING TO STUDENTS
Execution gate: PASS — every output below was produced by actually running the code in Python. Students' Part 3 wording/values vary; grade those on "does it run and produce the right kind of output."
Part 3 (model):
1. total_seconds = 200, then print(total_seconds // 60) → 3 and print(total_seconds % 60) → 20. ✓
2. subtotal = 20, tax = subtotal * 0.07, total = subtotal + tax, print(total) → 21.4 (a float, because of the * 0.07). ✓ (exact value varies if they pick a different subtotal)
3. Three type() lines printing <class 'int'>, <class 'float'>, <class 'str'> in some order. ✓
Part 4 trace table (run-verified):
| # | Program | Actual output |
|---|---|---|
| 1 | print(2 + 3 * 4) |
14 |
| 2 | print(10 / 2) |
5.0 |
| 3 | print(7 // 2) |
3 |
| 4 | print(7 % 2) |
1 |
| 5 | print(2 ** 3) |
8 |
| 6 | print(20 - 6 / 2) |
17.0 |
Python Tutor swap (run-verified): the program prints 2 then 1 — a and b end up swapped (a holds 2, b holds 1), with temp used to hold the old value of a during the swap.
Part 5 bugs (run-verified):
- Bug A quantity = "3"; total = quantity * price → prints 3333 (not 12). (i) Wrong output / a type bug; (ii) quantity is the string "3" (in quotes), and "3" * 4 repeats the text four times ("3333") instead of multiplying; (iii) fix: quantity = int("3") (or store quantity = 3 as a number) → print(quantity * price) → 12.
- Bug B print(total) before total = 5 + 3 → NameError: name 'total' is not defined. (i) A NameError / an order bug; (ii) the variable is used before it's assigned — Python runs top to bottom, and total doesn't exist yet on line 1; (iii) fix: assign first, then print:
python
total = 5 + 3
print(total)
→ 8.
Part 6 (expected): (1) most commonly #2 (5.0, not 5) or #6 (17.0, not 7.0 or 17). (2) / is true division and always returns a float (10 / 2 → 5.0); // is floor division and returns the whole-number part (7 // 2 → 3). (3) % is modulo — the remainder after division (7 % 2 → 1); real uses: testing even/odd, wrapping a clock, splitting items into groups with leftovers. (4) "3" is a string, so * repeated the text instead of multiplying; converting with int("3") (or storing 3 as a number) fixes it. (5) A type bug = a value is the wrong type (Bug A); an order bug = code in the wrong order, using a name before it exists (Bug B). type(quantity) would have shown <class 'str'>, revealing instantly that quantity was text, not a number.
Part 7 (AI-critique): full credit for a specific catch — most commonly the AI saying print(10 / 2) prints 5 instead of 5.0, or mixing up // and %. Full credit also if the student verified each AI claim by running it.
Grading rubric — 50 points
| Criterion | Full | Partial | None |
|---|---|---|---|
Part 3 — wrote & ran 3 programs (code + output shown; #1 uses // and %, #3 shows three types) (14) |
14 | 7–11 | 0–5 |
| Part 4 — trace table + swap (predictions attempted + all 6 actual outputs correct from running; swap predicted) (14) | 14 | 7–11 | 0–5 |
| Part 5 — found & fixed both bugs (problem + why + fix for the type bug and the order bug) (12) | 12 | 6–10 | 0–4 |
Part 6 — analysis (/ vs //, what % does, the string-repeat type bug, type-vs-order) (6) |
6 | 3–5 | 0–2 |
Part 7 — AI-critique (names a specific thing checked/corrected by running — ideally the 5.0 catch) (4) |
4 | 2 | 0–1 |
Quality gate (self-checked): every model output above (3, 20, 21.4, the three type() results, 14, 5.0, 3, 1, 8, 17.0, the swap 2/1, Bug A 3333 and its fix 12, Bug B NameError and its fix 8) was produced by actually running the code in Python — execution gate: PASS. No output is hand-traced. The lab grades the student's process (write → run → trace → debug), not a single fixed wording for the open-ended Part 3.
~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com