Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

In the "Guess the Number Game Python Code," after the user guesses the secret_number correctly, what is the immediate effect of the break statement?
Options
A It restarts the game with a new <code>secret_number</code>.
B It causes the program to exit the <code>while True</code> loop.
Correct Answer
C It prints "Try again!" and continues the loop.
D It prevents the <code>print("You Win!")</code> statement from executing.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The break statement, as explained on page 9, exits the loop instantly. In this case, it exits the while True loop after the correct guess.

Hint

Recall the definition of the break statement.

Question Info