Checking a number with its check digit on entry

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Checking a number with its check digit on entry

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A user types in an ISBN. What does the system do with the first 12 digits?
A Recalculates the check digit from them
B Stores them without any calculation
2. The recalculated check digit is 7 and the user entered 7 as the last digit. What happens?
A The number passes the check and is accepted
B The number is rejected and the user must re-enter it
3. The recalculated check digit is 5 but the user entered 7. What should the system do?
A Reject the number and ask the user to re-enter it
B Accept it because most of the digits are probably right
4. The first 12 digits of 978-0-306-40615-7 give a weighted sum of 93 (weights 1 and 3 alternating). What check digit should the system recalculate?
A 3, because 93 ends in 3
B 7, because 93 is 7 short of the next multiple of 10
5. A user types 978-0-306-04615-7, which is the valid ISBN with two digits swapped. The system recalculates the check digit as 5 and the user entered 7. What is the outcome?
A The check digits match, so the number is accepted
B The check digits differ, so the number is rejected

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1calc ← (10 - total MOD 10) MOD 10 ARecalculates the check digit from the weighted total of the other digits of the number that was entered
2IF calc <> entered THEN Bcalc = 7, entered = 7, so accept
3If the recalculated check digit differs from the entered one, the number is rejected and the user is asked to re-enter it CCompares the recalculated check digit with the entered one and runs the rejection code if they differ
4For the valid ISBN 978-0-306-40615-7, the recalculated check digit is 7, which matches the entered 7, so the number is accepted DThe recalculated check digit (5) differs from the entered one (7), so the number should be rejected, not accepted. Swapping two digits changed the total.
5978-0-306-04615-7 gives calc = 5, entered = 7, so ACCEPT EIF calc <> entered THEN OUTPUT "Please re-enter the number"
6IF calc = entered THEN OUTPUT "Please re-enter the number" FThe condition is the wrong way round. The re-enter message is shown when the check digits match, which is when the number is valid.

Definitions

recalculate and compare

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
calculated ← CalcCheckDigit(first12) IF calculated __ entered THEN OUTPUT "Re-enter the number"
2.
IF calculated <> entered THEN ______ "Re-enter the number" ENDIF
3.
calculated ← 5 entered ← 7 IF calculated <> _______ THEN reject
4.
IF calculated _ entered THEN OUTPUT "Number accepted" ENDIF
5.
WHILE calculated <> entered DO OUTPUT "Re-enter the number" _____ entered

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT code
B entered ← LastDigit(code)
C calc ← LastDigit(code)
D IF calc <> entered THEN
E OUTPUT "Re-enter number"
Question 2
A isbn ← "978030640615"
B calc ← CheckDigit(isbn)
C IF calc = LastDigit(isbn) THEN
D OUTPUT "Valid ISBN"
Question 3
A INPUT isbn
B calc ← CheckDigit(isbn) + 1
C IF calc = LastDigit(isbn) THEN
D OUTPUT "ISBN accepted"
E ELSE
F OUTPUT "Re-enter ISBN"
Question 4
A INPUT isbn
B calc ← CheckDigit(isbn)
C entered ← LastDigit(isbn)
D IF calc = entered THEN
E OUTPUT "Number rejected"
F ENDIF
Question 5
A total ← 93
B rem ← total MOD 10
C calc ← 10 + rem
D entered ← 7
E IF calc = entered THEN
F OUTPUT "ISBN accepted"

Answer Key

Checking a number with its check digit on entry
Section A: Quick Questions
Q1
A — Recalculates the check digit from them
Q2
A — The number passes the check and is accepted
Q3
A — Reject the number and ask the user to re-enter it
Q4
B — 7, because 93 is 7 short of the next multiple of 10
Q5
B — The check digits differ, so the number is rejected
Section B: Match the Pairs
Q1
calc ← (10 - total MOD 10) MOD 10 → Recalculates the check digit from the weighted total of the other digits of the number that was entered
Q2
IF calc <> entered THEN → Compares the recalculated check digit with the entered one and runs the rejection code if they differ
Q3
If the recalculated check digit differs from the entered one, the number is rejected and the user is asked to re-enter it → IF calc <> entered THEN OUTPUT "Please re-enter the number"
Q4
For the valid ISBN 978-0-306-40615-7, the recalculated check digit is 7, which matches the entered 7, so the number is accepted → calc = 7, entered = 7, so accept
Q5
978-0-306-04615-7 gives calc = 5, entered = 7, so ACCEPT → The recalculated check digit (5) differs from the entered one (7), so the number should be rejected, not accepted. Swapping two digits changed the total.
Q6
IF calc = entered THEN OUTPUT "Please re-enter the number" → The condition is the wrong way round. The re-enter message is shown when the check digits match, which is when the number is valid.
Section C: Definitions
Q1
recalculate and compare — Work out the check digit again from the other digits, then compare it with the one entered. If they differ, reject the number and ask the user to re-enter it.
Section D: Fill in the Blanks
Q1
calculated ← CalcCheckDigit(first12) IF calculated <> entered THEN OUTPUT "Re-enter the number"
Q2
IF calculated <> entered THEN OUTPUT "Re-enter the number" ENDIF
Q3
calculated ← 5 entered ← 7 IF calculated <> entered THEN reject
Q4
IF calculated = entered THEN OUTPUT "Number accepted" ENDIF
Q5
WHILE calculated <> entered DO OUTPUT "Re-enter the number" INPUT entered
Section E: Spot the Error
Q1
C — The check digit must be recalculated from the other digits with CheckDigit(code). Reusing the entered last digit means calc always equals entered, so errors are never found.
Q2
A — The valid ISBN-13 has 13 digits and ends in the check digit 7. The broken line drops that last digit, so there is no entered check digit to compare with. It should be "9780306406157".
Q3
B — The recalculated check digit must be used exactly as calculated. Adding 1 makes it wrong, so a valid ISBN would be rejected. It should be calc ← CheckDigit(isbn).
Q4
D — The number is rejected when the recalculated digit and the entered digit differ. The test must be calc <> entered. With = it rejects every valid number.
Q5
C — For the valid ISBN the weighted total is 93, so rem is 3. The check digit is 10 - 3 = 7, which matches the entered 7. Adding gives 13, which is wrong.