Part 03 / Topic 12 of 12
Putting it together: ATM with 3 PIN attempts
We simulate typed PINs with a list, so the program runs without input().
zip(range(1, 4), typed_pins) numbers the attempts and stops after 3, even if more PINs were typed.
CORRECT_PIN = "4321"
typed_pins = ["1111", "4321"] # what the user "typed"
for attempt, pin in zip(range(1, 4), typed_pins):
if pin == CORRECT_PIN:
print(f"Attempt {attempt}: PIN correct. Welcome!")
break
print(f"Attempt {attempt}: wrong PIN.")
else:
print("Card blocked. Too many wrong attempts.")
# Attempt 1: wrong PIN.
# Attempt 2: PIN correct. Welcome!
See the full menu version in examples/05_atm_menu.py.
Done here? The practice set for Part 3 — 7 exercises with solutions — is on the part page.