Input validation – OCR GCSE Computer Science lesson (J277)
Pupils learn to write range, length, type and presence checks in Python, and explain why validation cannot prove data is correct.
Lesson 8 of 14 in unit 11.1 Cyber Security and Robust Programs, taught in Year 11, Autumn 1. It answers one big question: How can a program refuse input that does not make sense?
By the end, pupils can write range, length, type and presence checks in Python, and explain why validation cannot prove data is correct.
- The Build (the main task)
- Write a function valid_size that returns True only if a shoe size is a whole number from 3 to 13, then use it in a loop that keeps asking until a valid size is entered.
- Support version
- Parsons problem: the validation loop's lines jumbled, with one distractor that uses or instead of and.
- Challenge
- Add a length check so a customer's postcode must be 6 to 8 characters, and a presence check so it cannot be blank.
- Real-world link
- Customers keep typing impossible shoe sizes like 0 and 70 into Kickstand's order form.
- Key words
- Validation, Range check and Acceptable, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “Validation checks that data is correct”; “A range check counts the number of characters”.
- OCR J277 specification
- 2.3.1 (defensive design: anticipating misuse, authentication, input validation, and maintainability (subprograms, naming conventions, indentation and comments)).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
Also sold in the Cyber Security and Robust Programs unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for GCSE Computer Science (OCR)
See allPupils learn to describe how viruses, worms, trojans, spyware and ransomware work and the harm each can do to a business like Kickstand.
Free sample lessonPupils learn to write and call a procedure and a function in Python, and explain the difference between them and why subprograms are reused.
Pupils learn to describe phishing and other social engineering, spot the signs in a fake message, and explain how staff training reduces the risk.
Written for the specifications named. Not endorsed by or affiliated with any exam board.