Unit 2 Task 16 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 16: ATM PIN (three tries)

← Back to task


One possible program:

correct = "2468"
attempts_left = 3

while attempts_left > 0:
    pin = input("Enter PIN: ")
    if pin == correct:
        print("Welcome")
        break
    attempts_left -= 1
    if attempts_left > 0:
        print("Wrong. Tries left:", attempts_left)
    else:
        print("Card locked")