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

A program uses this while loop to count down:count = 5while count > 0:print(count)Which issue is preventing the loop from working correctly?
B) It runs infinitely because count is never modified.
A) There is a missing colon after the condition.
C) The condition should use >= instead of >.
D) The variable should be named differently.

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
Ben
9 hours ago
I feel like the condition should be using >= instead of >, but I'm not entirely confident about that.
upvoted 0 times
...
Gwenn
6 days ago
I'm not sure, but I remember something about needing a colon after the while condition. Could that be the issue?
upvoted 0 times
...
Delisa
11 days ago
I think the loop might run infinitely because count isn't being modified inside the loop. That sounds familiar from practice questions.
upvoted 0 times
...
Aleshia
16 days ago
I don't think the variable name is the issue here, but I could be wrong. It seems like a minor detail compared to the loop logic.
upvoted 0 times
...
Lili
2 months 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
2 months 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
2 months 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