Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

Consider the following code snippet from Slide 5:
count = 1
while count ≤ 5:
    print('Number:', count)
    count = count + 1

What is the *last* number printed by this loop?
Options
A 1
B 5
Correct Answer
C 6
D The loop never ends.
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.

Question Info