Robust programs: validation and testing

Users type the strangest things: their age as 150, a blank name, or a word where a number should be. A robust program checks its input and is tested before anyone uses it.

Practise this lesson free (7 questions)

Validation checks

Validation is the program checking that input is sensible and allowed before using it.
Validation cannot check that data is true: a pupil could still type 12 when they are 13.
CheckWhat it checksExample
Range checka number is between limitsage is from 11 to 16
Presence checksomething has been enteredname is not blank
Length checkthe number of charactersa password has at least 8 characters
Type checkthe data is the right typeage is a whole number
Format checkthe data follows a patterna date is written dd/mm/yyyy

Validation in Python

A while loop keeps asking until the input is valid:
age = int(input("Age (11 to 16)? "))
while age < 11 or age > 16:
    print("Not valid, try again")
    age = int(input("Age (11 to 16)? "))
print("Thanks, age", age)
If the user types 20, then 9, then 14, the messages printed (as well as the prompts) are:
Not valid, try again
Not valid, try again
Thanks, age 14
This is a range check. Using len(name) == 0 instead would be a presence check.

Testing with test data

Programmers test with three kinds of data. For the range 11 to 16:
TypeMeaningExamplesShould it be accepted?
Normaltypical data that should be accepted13, 14yes
Boundaryvalues at the edges of the allowed range11 and 16 (and just outside: 10, 17)11, 16 yes; 10, 17 no
Erroneousdata that should be rejected50, -3, "twelve"no
Worked example

A program asks for a test mark from 0 to 50. Give one normal, one boundary and one erroneous test value, and say what should happen.

  1. Normal: 30, which should be accepted.
  2. Boundary: 50, the top edge, which should be accepted (51 should be rejected).
  3. Erroneous: 75 or a word such as "ten", which should be rejected with a message.

Answer: For example: 30 (accept), 50 (accept), 75 (reject).

Key idea

Validation checks input is sensible before it is used: range, presence, length, type and format checks. Test with normal, boundary and erroneous data to prove the program copes with anything.

Key words
AND
A Boolean operator that gives True (1) only when both inputs are True.
Program
A set of instructions written in a programming language that a computer can run.
Input
Data put into a computer, for example from a keyboard, mouse, microphone or sensor.
While loop
A condition-controlled loop that repeats while its condition is True.
NOT
A Boolean operator that flips its input: True becomes False and False becomes True.

All KS3 Computing key terms and definitions →

Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. A form will not let you leave the surname box blank. Which check is this?

    1. Length check
    2. Range check
    3. Type check
    4. Presence check
    Show the answer

    Answer: Presence check

    Something must be entered.

  2. A username must be no more than 12 characters. Which check is this?

    1. Range check
    2. Length check
    3. Presence check
    4. Format check
    Show the answer

    Answer: Length check

    Counting characters is a length check.

Check you have got it

Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.

Related lessons