Exam-style question
Try this first
Consider this pseudocode: number <- 2 total <- 0 WHILE number <= 8 total <- total + number number <- number + 2 END WHILE OUTPUT total Hand-trace the algorithm, state its output, and convert it into Python. Then give one test input or test case and explain how logical reasoning and user feedback could be used when arguing that the resulting program is correct and efficient.
Answer and explanation
Concise answer
Trace:
Why this is correct
A hand trace records changing values after each step and exposes the final output. The Python version preserves the sequence, assignments, selection condition in the while loop, and iteration. Correctness can be supported by tracing and suitable test data, while user feedback can check whether the program's behaviour and output meet the user's expectations.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
