Practice

Validated PIN Entry

EASYValidation6 marks

Keep asking the user to enter a PIN until it has exactly 4 characters.

For each invalid PIN:

  • output Too short if it has fewer than 4 characters
  • output Too long if it has more than 4 characters

When a valid PIN is entered, output Accepted.

Input: One or more PIN strings. Output: Error messages for invalid attempts, then Accepted.

Example:

Input:  12
        12345
        9081
Output: Too short
        Too long
        Accepted
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Short, long, then valid
Inputs: 12, 12345, 9081
Expected: Too short Too long Accepted
Test 2: Valid first time
Inputs: 1357
Expected: Accepted