Exercise 3: Three Password Attempts — Possible Solution ==================================================================== SECRET = "open sesame" for attempt in range(1, 4): password = input(f"Password (attempt {attempt} of 3): ") if password == SECRET: print("Access granted") break print("Wrong password") else: print("Too many attempts. Account locked.") Example run: Password (attempt 1 of 3): letmein Wrong password Password (attempt 2 of 3): 123456 Wrong password Password (attempt 3 of 3): password Wrong password Too many attempts. Account locked. Second run: correct on the second attempt: Password (attempt 1 of 3): hello Wrong password Password (attempt 2 of 3): open sesame Access granted WHY THIS WORKS AS AN ANSWER ------------------------------ range(1, 4) gives 1, 2, 3, so three passes. A correct password hits break, which skips both the rest of the loop and the else block, so 'Account locked' is never printed after a success. If the loop runs out of attempts without a break, the else runs. The alternative is a found flag set to True before the break and checked after the loop; for/else says the same thing with one less variable.