A program uses this while loop to count down:
count = 5
while count > 0:
print(count)
Which issue is preventing the loop from working correctly?
The loop condition is:
while count > 0:
At the start, count is 5, so the condition is true. The program prints the value of count.
However, inside the loop, the value of count is never changed. That means count always stays 5, so the condition count > 0 is always true. As a result, the loop runs forever.
A corrected version would be:
count = 5
while count > 0:
print(count)
count = count - 1
This decreases count by 1 during each loop iteration. Eventually, count becomes 0, and the condition count > 0 becomes false.
Therefore, the correct answer isB. It runs infinitely because count is never modified.
Lili
17 days agoLisandra
22 days agoMyra
27 days ago