Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

Examine the following code snippet from Slide 11:
num = 10
while num > 0:
    print(num)
    num = num + 1

What will happen when this code runs?
Options
A The loop will never start.
B It will print numbers from 10 down to 1.
C It will cause an infinite loop.
Correct Answer
D It will print only the number 10 and then stop.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The variable num starts at 10. The condition num > 0 is True. Inside the loop, num is incremented (num = num + 1), so it will become 11, 12, etc., always remaining greater than 0. Thus, the condition will never become False, leading to an infinite loop.

Hint

Pay close attention to how the `num` variable is updated inside the loop.

Question Info