Case-based lecture: you attempt, we discuss, then we reveal.
cs-013, cs-014, cs-015, cs-016Read lines until the sentinel 'done'; echo each line uppercased, but skip lines longer than 20 characters (count them instead).
lines = ["coffee", "x" * 21, "tea", "done", "late"]
skipped = 0
for line in lines:
if line == "done":
break
if len(line) > 20:
skipped += 1
else:
print(line.upper())
print(skipped)Expected: COFFEE then 1
Cost: O(total input length). Python: `while True:` + `break` mirrors the flowchart's loop with two exits.
Given a list of course codes, remove empty strings and duplicates (keeping first occurrences), and report how many entries were dropped.
Expected: ['CS1', 'MA2'] 2
Cost: O(n^2) with the list-membership check; the set version (lecture 13) is O(n) - say so, then wait.
Price 2.35. The customer pays with coins 1.00, 1.00, 0.50. Compute credit as coins arrive, then change as 20/10/5-cent breakdown.
Expected: credit 250, change 15 -> [10, 5]
Cost: O(coins + denominations). The greedy breakdown works for this coin system - lecture 23 returns to when greedy is trustworthy.
Place requests into 5 slots, 1 hour each, max 2 meetings per slot, respect 'not on Friday'. Print the schedule and the refused requests.
Expected: schedule slots 1-4 used; refused: [Friday request]
Cost: O(requests x slots). Greedy first-fit is fine here; question for fast finishers: when does first-fit waste capacity?
Read numbers until a sentinel 0, then output how many were read, their sum, and the largest. First translation from pseudocode to real Python.
**Input:** input numbers: 4, 9, 2, 9, 0 (sentinel)**Output:** count 4, sum 24, largest 9Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-013 — not embedded in this deck.
Given a list of course names with stray spaces and duplicates, produce a clean numbered list. Introduces list traversal and building output.
**Input:** [" CS1 ", "DS1", "CS1", " Stats "]**Output:** 1. CS1 2. DS1 3. Stats (trimmed, deduplicated, numbered)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-014 — not embedded in this deck.
Compute change in coins (25/10/5/1) for an amount. Emphasise state updates of remaining amount and each coin count, and why order of subtraction matters.
**Input:** amount 87 cents**Output:** 25x3, 10x1, 5x0, 1x2Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-015 — not embedded in this deck.
Given busy intervals and a meeting length, output all possible start times in a day. First encounter with walking through sorted intervals.
**Input:** busy [(9,10), (11,12.5)]; day 8..18; meeting 1.5 h**Output:** starts at 12.5, 13.0, 13.5, ..., 16.5 (9 starts; the 8-9 and 10-11 gaps are each too short for 1.5 h)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-016 — not embedded in this deck.