cs-013 — Echo with Limits
| Field | Value |
|---|---|
| id | cs-013 |
| difficulty | Beginner |
| topics | python, io, state |
| lecture | lecture-04 |
| 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
Read numbers until a sentinel 0, then output how many were read, their sum, and the largest. First translation from pseudocode to real Python.
Your deliverable is the computed aggregates for the worked instance, the accumulator update rules, and one test input that breaks a careless initialisation. 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: input numbers: 4, 9, 2, 9, 0 (sentinel)
- Output: count 4, sum 24, largest 9
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
- Three state variables updated in one loop; largest must start from the first number, not 0.
- Every aggregate here is a small machine: state + update rule.
- The initial value is part of the algorithm, not a detail.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Which accumulator was hardest to get right, and what test would have caught the mistake?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: python, io, state.
- 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: Implement your pseudocode and verify it against your hand trace.