Exercise 9: A PIN Check With Three Attempts and No break — Possible Solution ==================================================================== CORRECT_PIN = "1234" attempts = 0 authenticated = False while attempts < 3 and not authenticated: pin = input(f"Enter PIN (attempts left: {3 - attempts}): ") attempts += 1 authenticated = (pin == CORRECT_PIN) if not authenticated: print("Incorrect PIN") if authenticated: print("Welcome") else: print("Card retained") Example run: Enter PIN (attempts left: 3): 1111 Incorrect PIN Enter PIN (attempts left: 2): 2222 Incorrect PIN Enter PIN (attempts left: 1): 1234 Welcome Second run: three wrong PINs: Enter PIN (attempts left: 3): 1 Incorrect PIN Enter PIN (attempts left: 2): 2 Incorrect PIN Enter PIN (attempts left: 1): 3 Incorrect PIN Card retained WHY THIS WORKS AS AN ANSWER ------------------------------ The loop continues only while BOTH parts of the condition are true: attempts remain and the user is not yet authenticated. Either part turning false ends it: using up the third attempt, or entering the right PIN. Both are changed inside the body, so the loop cannot run forever. After the loop, the flag tells you which of the two reasons ended it. The prompt uses 3 - attempts, calculated before the counter goes up, so it shows 3, 2, 1. A correct PIN on the first try leaves attempts at 1, so nothing is 'retained'.