Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

Analyze the following Python code from page 11: num = 10; while num > 0: print(num); num = num + 1. What is the error in this code?
Options
A The loop will never start because <code>num</code> is not greater than 0.
B The code works perfectly, printing numbers from 10 upwards.
C It is an infinite loop because <code>num</code> keeps increasing, always satisfying <code>num > 0</code>.
Correct Answer
D It will print 10, then 1, then stop.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The variable num starts at 10. In each iteration, num is incremented (num = num + 1), so it becomes 11, then 12, and so on. Since num is always increasing, the condition num > 0 will always remain True, creating an infinite loop.

Hint

Pay close attention to how the num variable is updated and its relationship to the loop condition.

Question Info