Question Detail
Question
Consider the following code snippet from Slide 5:
What is the *last* number printed by this loop?
count = 1
while count ≤ 5:
print('Number:', count)
count = count + 1What is the *last* number printed by this loop?
Correct Answer
Option B is the correct answer.
Detailed Explanation
The loop prints 'Number: 1', 'Number: 2', 'Number: 3', 'Number: 4', 'Number: 5'. When
count becomes 6, the condition count ≤ 5 becomes false, and the loop terminates. So, the last number printed is 5.
Hint
Trace the loop's execution and when the condition becomes false.