Learn first
Programs follow precise instructions
A program is a set of instructions. A variable stores a value. A condition chooses between paths. A loop repeats steps. Output is the result produced.
How to work it out Trace one instruction at a time. Keep a record of values and check exactly when a condition or repeated step is evaluated.
A separate example In a separate trace, start with n = 2, add 3, then double n. The two instructions happen in order: 5 is an intermediate value before the final result.
Requirement: accept whole-number levels from 1 through 5, inclusive. Valid types are integers only. Build tests for each endpoint, just outside each endpoint, an ordinary interior value and a wrong type. A passing sample is evidence, not a universal proof.
Worked example
For integer inputs 0, 1, 3, 5 and 6, expected outcomes are reject, accept, accept, accept and reject. The text "3" is rejected under this contract even though it contains a digit.