cs-053 — The Validator Trio
| Field | Value |
|---|---|
| id | cs-053 |
| difficulty | Beginner |
| topics | functions, reuse |
| lecture | lecture-14 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | none |
| objective | state inputs, outputs, and assumptions, then solve a small instance by hand |
| solution | held by the instructor; discussed after the attempt |
Problem
Three validation checks (email-ish, phone-ish, id format) become three functions plus a driver. Naming, single purpose, return vs print.
Your deliverable is the function list with contracts, the composed driver, and one input per function that exercises its edge. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: values: "ada@uni.edu" (ok-ish), "07123 456789", "S2023/4471"
- Output: three independent verdict functions + a driver printing a table
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Each check returns True/False; the driver does the printing. Contracts first, code second.
- A good function name is a miniature specification.
- Return values compose; printed output does not.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Where would this decomposition crack if the input format changed?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: functions, reuse.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a first attempt; partial answers with clear reasoning are worth more than silent struggling.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Split one function into two and defend the new contract boundary.