You only have three attempts.

A four digit personal identification number (PIN) is required to access a system. If the user enters the PIN correctly they can continue. If the user enters the PIN incorrectly they are prompted for their PIN again. There are a maximum of three attempts, after which the user is locked out for security.


Write a program that asks the user to enter their PIN. If they enter the incorrect PIN three times, the program outputs, "Locked out." If they correctly enter 7528 the program outputs, "Security check passed."

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Create a subprogram called `get_pin` that:

  1. Asks the user to enter their PIN.
  2. The input is compared against the valid PIN 7528.
  3. If the input is incorrect the user is prompted for the PIN again a maximum of three times.
  4. The function returns True if the PIN is valid.
  5. The function returns False if the PIN is invalid.

Complete the `main program` so that:

  1. The subprogram `get_pin` is called.
  2. The message, "Security check passed" is output if the validation is passed.
  3. The message "Locked out." is output if the user fails to enter the correct PIN after three attempts.

Typical inputs and outputs from the program would be:

Enter PIN: 2311

Enter PIN: 2213

Enter PIN: 7895

Locked out.

Enter PIN: 6753

Enter PIN: 9622

Enter PIN: 7528

Security check passed.

Enter PIN: 7528

Security check passed.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:


Run the unit tests below to check that your program has met the success criteria.

Enter PIN: 1111

Enter PIN: 2222

Enter PIN: 3333

Locked out.

Enter PIN: 7528

Security check passed.

Enter PIN: 7582

Enter PIN: 7285

Enter PIN: 7528

Security check passed.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.