Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

Consider the Python code snippet:
count = 1
while count <= 5:
    print("Number:", count)
    count = count + 1

What will be the last number printed by this loop?
Options
A 1
B 5
Correct Answer
C 6
D 0
Correct Answer

Option B is the correct answer.

Detailed Explanation

The loop runs as long as count <= 5. When count is 5, it prints "Number: 5" and then count becomes 6. At this point, count <= 5 is False, and the loop terminates.

Hint

Trace the value of count just before the loop condition becomes false.

Question Info