Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

In the 'Guess the Number Game Python Code' example, why is while True: used?
Options
A To ensure the loop runs a fixed number of times.
B To make the loop conditional on an external factor.
C To create an infinite loop that can only be exited by a <code>break</code> statement.
Correct Answer
D To signal that the loop will only run if a certain condition is met initially.
Correct Answer

Option C is the correct answer.

Detailed Explanation

Page 12 and 13 show while True: combined with an if guess == secret_number: break structure. This setup creates a loop that would run indefinitely (as True is always true) until the break statement is encountered when the correct guess is made.

Hint

Consider the effect of True as a condition and how the break statement is used in conjunction with it to provide an exit.

Question Info