Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

Consider the following Python code snippet:
num = 10
while num > 0:
    print(num)
    num = num + 1

What is the outcome when this code is executed?
Options
A It will print numbers from 10 down to 1 and then stop.
B The loop will never start because <code>num</code> is initialized to 10.
C It will result in an infinite loop, continuously printing numbers that keep getting larger.
Correct Answer
D It will print 10 and then stop, as the condition <code>num > 0</code> becomes false.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The initial num is 10, which satisfies num > 0. Inside the loop, num is incremented (num = num + 1). This means num will always be greater than 0 (10, 11, 12, ...), so the condition num > 0 will always be True, leading to an infinite loop.

Hint

Pay close attention to how the num variable is updated inside the while loop. Does it ever make the condition num > 0 false?

Question Info