Two digits swapped
A librarian types a long card number. She swaps two digits by accident. Both numbers look fine, and both could belong to real pupils.
Checking the size of the number cannot see the slip. Counting the digits cannot either. A different kind of check can.
Key words
| Word | What it means | Example |
|---|---|---|
| Check digit | an extra digit, worked out from the other digits, added to the end of a number | |
| Weight | the number a digit is multiplied by, set by its place | |
| Modulus | the remainder left after dividing | 67 divided by 10 leaves 7 |
| Transposition | two digits swapped by mistake | |
| Validation | a check that data is sensible when it is entered |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can work out a check digit, use it to test a number, and say which mistakes it catches.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
How a check digit works
The system takes the digits and does a sum on them. The answer becomes one extra digit, stuck on the end.
When the number is typed again, the system repeats the sum. If the last digit does not match the answer, a slip has happened.
Our library card scheme
A card has six digits and a check digit. Multiply the digits by 1, 2, 3, 4, 5 and 6 from the left. Add the answers. The check digit is the last digit of the total.
Real schemes work the same way with other weights. The 13-digit number on a book, the ISBN, uses weights of 1 and 3 in turn.
Worked example: card 402173
| Digit | Weight | Digit times weight |
|---|---|---|
| 4 | 1 | 4 |
| 0 | 2 | 0 |
| 2 | 3 | 6 |
| 1 | 4 | 4 |
| 7 | 5 | 35 |
| 3 | 6 | 18 |
| Total | 67 | |
| Check digit: last digit of 67 | 7 |
The cells students fill in are left blank in this preview.
Try it: work it out in Python
digits = "402173"
total = 0
place = 1
for ch in digits:
total = total + int(ch) * place
place = place + 1
print("total", total)
print("check digit", total % 10)
# Swap the 0 and the 2: use "420173". What is the check digit now?
Check
Have a go
Check
4 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.