Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Defensive Design

Validation checks

All topicsPractise exam questions
Knowledge organiser

Defensive Design

301.16b

Range length presence.

What you need to know

Validation checks ensure data meets specific criteria before processing. Common checks include range (within limits), length (correct size), and presence (not empty).

Key points

  • Range check: 0 <= age and age <= 120
  • Length check: len(password) >= 8
  • Presence check: name != ""
  • Type check: value.isdigit()
  • Use while loops to re-ask until valid

Code examples

Validation loop
python
age = -1
while age < 0 or age > 120:
    age = int(input("Enter age (0-120): "))
    if age < 0 or age > 120:
        print("Out of range, try again")
print("Age: " + str(age))