Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.3: Checking each field before it is saved

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

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

WordWhat it means
Validationa check that data is sensible when it is entered
Verificationa check that data was copied correctly
Fieldone box in a record, such as year group
Presence checkis something entered at all?
Length checkis the number of characters allowed?
Range checkis the number between a low and a high limit?
Type checkis it the right kind of value, such as a whole number?
Format checkdoes it follow the right pattern?
Check digitan 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The checks and what each one asks

CheckAsksUse it forExample that fails
PresenceIs it there?A field that must be filledEmpty name box
LengthRight number of characters?Codes, passwords, phone numbersPassword of 3 letters
RangeBetween the limits?Year groups, ages, quantitiesYear group 99
TypeRight kind of value?A box that must be a numberThe word eleven
FormatRight pattern?Dates, emails, survey codesCode S1042 with no hyphen
Check digitDoes the last digit fit the others?Long numbers typed by handA card number with two digits swapped

The cells students fill in are left blank in this preview.

Try it: three checks on one answer

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.