Question Detail
Question
Analyze the following Python code from the "Can you find the error?" section:
What type of error does this code contain?
num = 10
while num > 0:
print(num)
num = num + 1What type of error does this code contain?
Correct Answer
Option D is the correct answer.
Detailed Explanation
The goal is to print 10 to 1, but
num starts at 10 and increases (num = num + 1). This means num will always be greater than 0, making the condition num > 0 perpetually True, leading to an infinite loop.
Hint
Trace the value of
num with each iteration. Does it ever become 0 or less?