Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

WGU Foundations of Programming Python Exam - Topic 2 Question 1 Discussion

Actual exam question for WGU's Foundations of Programming Python exam
Question #: 1
Topic #: 2
[All Foundations of Programming Python Questions]

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?

Show Suggested Answer Hide Answer
Suggested Answer: B

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.


Contribute your Thoughts:

0/2000 characters
Lili
17 days ago
I feel like I've seen a question like this before, and it was about the condition needing to be >= instead of just >.
upvoted 0 times
...
Lisandra
22 days ago
I'm not entirely sure, but I remember something about needing a colon after the while condition. Could that be it?
upvoted 0 times
...
Myra
27 days ago
I think the loop might run infinitely because count is never modified inside the loop. That seems like a common mistake.
upvoted 0 times
...

Save Cancel