Question Detail

BIO 107 While Loops & Control Flow Objective Question

Question

In the 'ATM Security Check' example on page 6, the while loop condition is while pin != "1234":. What is the intended behavior of this loop?
Options
A It runs only once and then exits, regardless of the PIN.
B It continuously prompts the user for a PIN until the correct PIN ('1234') is entered.
Correct Answer
C It grants access immediately and then asks for the PIN.
D It waits for 1234 seconds before granting access.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The text states, 'Wait for the user to provide the correct PIN before granting access.' and 'This loop runs forever until the correct PIN is entered.' The condition pin != "1234" means the loop continues as long as the input PIN is not '1234'.

Hint

The '!=' operator means 'not equal to'. The loop continues as long as the condition is true.

Question Info