Case-based lecture: you attempt, we discuss, then we reveal.
cs-061, cs-062, cs-141, cs-063, cs-064Lines 'ada,CS1,80', 'bo,DS1,' (missing), 'ada,CS1,95', 'cy,CS1,300' (over 100). Produce per-student averages plus flags for missing and anomalous scores.
lines = ["ada,CS1,80", "bo,DS1,", "ada,CS1,95", "cy,CS1,300"]
missing, anomaly, acc = [], [], {}
for ln in lines:
name, course, score = [p.strip() for p in ln.split(",")]
if score == "":
missing.append(name)
continue
s = float(score)
if not 0 <= s <= 100:
anomaly.append((name, s))
continue
acc.setdefault(name, []).append(s)
avg = {k: sum(v) / len(v) for k, v in acc.items()}
print(avg["ada"], missing, anomaly)Expected: ada 87.5; missing: bo; anomaly: cy with 300
Cost: O(n) for n lines - one pass, flags accumulate alongside.
For "Data science is twenty percent practice and eighty percent cleaning data." report word count, reading time (200 wpm), the longest word, and the two most frequent words - in one pass.
text = "Data science is twenty percent practice and eighty percent cleaning data."
words = text.split()
n = len(words)
longest = max(words, key=len)
tally = {}
for w in words:
tally[w] = tally.get(w, 0) + 1
top = sorted(tally.items(), key=lambda kv: (-kv[1], kv[0]))[:2]
print(n, round(n / 200 * 60, 1), longest)
print(top)Expected: words 11; reading time 3.3 s; longest 'practice'; top: percent(2), then a one-count tie
Cost: O(n) time, O(u) space; the naive alternative (recount per aggregate) is still O(n) but four passes.
Answers 'yes', 'no', 'YES!!', '', 'maybe, idk', and multi-select '1,3'. Define a coding scheme and apply it.
def code(answer):
a = answer.strip().strip("!?").lower()
return {"yes": 1, "no": 0}.get(a, None)
samples = ["yes", "no", "YES!!", "", "maybe, idk", "1,3"]
coded = [code(s) for s in samples]
print(coded)Expected: yes=1, no=0, YES!!=1, ''=missing, 'maybe, idk'=missing, '1,3'=missing (not multi-select here)
Cost: O(n) over answers; the scheme costs nothing at runtime because it was decided at design time.
Challenge 1: sum the digits of 2^15. Challenge 2: estimate the longest run of heads in 100 fair coin flips. Five minutes for both.
big = 2 ** 15
s = sum(int(d) for d in str(big))
print(s)Expected: 26; typical longest heads-run in 100 flips: 6-7
Cost: Digit sum O(digits). Streak simulation O(trials x 100); exact DP exists but is overkill here.
From raw score lines (student, course, score) build a per-student average and flag anomalies. Integrates parsing, dicts, aggregation, and a written policy for anomalies.
**Input:** lines: "ada,CS1,80", "bo,DS1,", "ada,CS1,95", "cy,CS1,300"**Output:** averages: ada 87.5, bo (missing score: flagged), cy 300 (anomaly: flagged by policy > 100)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-061 — not embedded in this deck.
Compute reading-time, longest word, and word-frequency histogram for a text without importing anything beyond basics. Multi-part but small; the skill is planning.
**Input:** "Data science is twenty percent practice and eighty percent cleaning data."**Output:** words 12, reading time 12/200*60 = 3.6 s, longest word 'practice', top: data/percent by countSolve 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-062 — not embedded in this deck.
Your team's script auto-refunds campus print credit under this rule — it is correct and deployed:
**Input:** the deployed rule, the 5-minute sampling fact**Output:** a six-sentence memo covering the rule, the samplingcaveat, and the manager's threshold decisionSolve for the worked instance first. Then ask what would change if onePseudocode, 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-141 — not embedded in this deck.
Given messy survey responses (free text, multi-select), define a coding scheme, then count. The task is as much designing the representation as coding it.
**Input:** answers: "yes", "no", "YES!!", "", "maybe, idk", multi-select "1,3"**Output:** coding scheme: yes=1 (case-insensitive, strip punctuation), no=0, else missing; multi-select split on commaSolve 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-063 — not embedded in this deck.
Two previously unseen small problems, 10 minutes each, in exam conditions. Then a guided self-review with a rubric. Consolidation as rehearsal, plus a look ahead to Block III.
**Input:** challenge 1: sum of digits of 2^15 = 32768 -> 26; challenge 2: longest run of heads in 100 coin flips (simulated)**Output:** 26; and a run of about 6-7 (verify distribution by repeated simulation)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-064 — not embedded in this deck.