The year group of 99
A school survey asks pupils for their year group. When the answers come back, one pupil is in year 99. Another typed "eleven". Three left the box empty.
Every one of these would have been stopped at the moment of typing, if the form had checked the box.
Key words
| Word | What it means |
|---|---|
| Validation | a check that data is sensible when it is entered |
| Verification | a check that data was copied correctly |
| Field | one box in a record, such as year group |
| Presence check | is something entered at all? |
| Length check | is the number of characters allowed? |
| Range check | is the number between a low and a high limit? |
| Type check | is it the right kind of value, such as a whole number? |
| Format check | does it follow the right pattern? |
| Check digit | an extra digit worked out from the others, used to catch typing mistakes |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can say what each validation check does, choose the right one for a field, and write the checks in Python.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
The checks and what each one asks
| Check | Asks | Use it for | Example that fails |
|---|---|---|---|
| Presence | Is it there? | A field that must be filled | Empty name box |
| Length | Right number of characters? | Codes, passwords, phone numbers | Password of 3 letters |
| Range | Between the limits? | Year groups, ages, quantities | Year group 99 |
| Type | Right kind of value? | A box that must be a number | The word eleven |
| Format | Right pattern? | Dates, emails, survey codes | Code S1042 with no hyphen |
| Check digit | Does the last digit fit the others? | Long numbers typed by hand | A card number with two digits swapped |
The cells students fill in are left blank in this preview.
Try it: three checks on one answer
answer = "11"
print(len(answer) > 0)
print(answer.isdigit())
print(int(answer) >= 7 and int(answer) <= 13)
# Change the answer to eleven. Which line is False, and which line breaks?
# Change it to 99. Which line is False now?
Validation in a spreadsheet
Important
Spreadsheet programs have a data validation setting. Pick a column and a rule, such as a whole number from 7 to 13. It then refuses anything else. This platform has no spreadsheet, so you write the same rules in Python.
Check: pick the check
Have a go
Check: pick the check
5 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.