Translate the rule before the code
Suppose a fictional shop offers free delivery when a basket subtotal is at least 50 dollars. The condition subtotal >= 50 includes equality; subtotal > 50 excludes it. An if statement chooses a branch according to its condition. Decide what the rule means before choosing the operator. Ask whether the threshold applies before or after discounts and whether delivery is available in the customer’s area.
Worked example: three baskets
Test subtotals of 49, 50, and 51. Under the stated rule, the first basket pays delivery and the other two qualify. Under the mistaken condition subtotal > 50, the 50-dollar basket pays delivery too. Testing only 60 dollars would miss the defect because both versions qualify that basket. The boundary case distinguishes the intended rule from a plausible implementation error.
Separate invalid input from a valid decision
A missing subtotal is not the same as a zero-dollar subtotal. Validate incoming data before applying the rule. If several conditions must hold, write their relationship explicitly: threshold met AND delivery area supported. If there are exceptions, specify their priority. A program can apply a rule consistently even when the rule itself is incomplete, unfair, or unsuitable; testing behavior does not settle policy.
Put it to work
Write three test inputs for a rule that accepts ages 18 and above. Then add a missing-input case and state its expected handling.
Knowledge check
Sources & further reading
- Python tutorial: if statements ↗
Language concepts and syntax. The scenarios, calculations, exercises, and questions are original Institute teaching.