1.Why should I care?
The term project brings everything together: precise steps, types, formulas, decisions, loops, functions, tests and debugging. Engineers spend real time planning before coding, because a clear plan makes the code short and the testing obvious.
- ◇ Turn a project brief into precise requirements and an ordered algorithm.
- ◇ Decompose the program into functions with clear inputs, outputs and docstrings.
- ◇ Design a test log that exercises every branch, including malformed and boundary lines.
2.Predict
The brief says 'flag the machine if it gets too hot'. What should you do first?
Guess first. Being wrong here is how the surprise works.
3.Understand
From brief to requirements
The brief: read a temperature log, flag readings outside a safe band, report the mean, minimum and maximum, and decide whether the machine needs inspection. Requirements: safe band 10–60 °C inclusive; a line that won't convert is malformed and counted; report INSPECT if any reading is outside the band or more than 2 lines are malformed, otherwise OK; an empty log reports 'no readings' and INSPECT.
Decompose into functions
parse_reading(line) → float or None. summarise(values) → (mean, min, max). count_outside(values, low_c, high_c) → int. decide(values, malformed) → "INSPECT" or "OK". A short main program reads the lines, calls these and prints the report. Write a one-sentence docstring for each before writing its body.
Design the test log to break it
Include: normal readings; exactly 10.0 and 60.0 (safe); 9.9 and 60.1 (outside); ERR, a blank and −999.0; exactly 2 and then 3 malformed lines; and an empty log. Write the expected report for each test log by hand, from the requirements, before running anything.
Explain it another way
Planning is drawing the map before the journey. It's quicker to fix a wrong turn on the map than halfway up the wrong mountain.
Requirements define observable behaviour; the decomposition defines interfaces (function signatures and contracts); the test plan defines how each requirement is verified, including equivalence classes and boundaries.
Condition-monitoring tools in factories implement this logic at scale: thresholds from the equipment manufacturer, data-quality counts and a simple, auditable decision rule.
Worked example 1
Test log: 25.0, 10.0, 60.0, ERR, ERR. What report should the checker give?
Good readings 25.0, 10.0, 60.0: mean 31.67 °C, min 10.0, max 60.0. Outside the band: 0 (10.0 and 60.0 are inside, inclusive). Malformed: 2, which is not more than 2. So the decision is OK. Add one more ERR and it must become INSPECT: a boundary test on the malformed count.
Common mix-ups
- Planning is wasted time; real engineers just code.
✓ A few minutes of planning saves hours of rework, and the plan becomes your test list and your report. - Test data should be realistic, so normal readings are enough.
✓ Test data should be designed to break the program: boundaries, malformed lines, empty logs.
4.Discover
Choose 'Sensor-log checker'. Order the six steps and mark the vague ones, then compare with the precise versions. Use the result as the skeleton of your plan: one function for each step that does real work.
Loading the interactive…
Can't use the interactive? Read a description instead
The step orderer's 'Sensor-log checker' lists six steps to order: open the log and read it a line at a time; skip and count lines that do not convert; add good readings to a list; compute mean, minimum and maximum; count readings outside 10–60 °C; report INSPECT if any are outside or more than 2 lines were malformed, otherwise OK. Two steps start vague ('Skip the bad lines', 'Flag the machine if it seems too hot').
5.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
The safe band is 15–45 °C inclusive. Readings (°C): 44, 33, 28, 29, 20, 23, 49, 49, 24, 12, 33, 24. What percentage of the readings are outside the band?
Practice 2
Which test log best checks the safe-band boundary?
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 3
What should the checker do with an empty log?
Practice 4
Why write each function's docstring before its body?
7.Apply it
Write your project plan: the requirements (with numbers), the four function signatures with docstrings, a flowchart or numbered algorithm for the main program, and at least three test logs with their expected reports worked out by hand.
8.Reflect
9.Go further
- Academy: files and CSV data ↗How to read a log file line by line when you work on your own computer.
Concepts: Decomposition, algorithms and flowcharts · Functions and decomposition · Lists, dictionaries and tabular data