← IGCSE Computer Science Paper 1

Checking a number with its check digit on entry

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.

Understanding Checking a number with its check digit on entry in IGCSE Computer Science Paper 1

What it does: A mismatch means the number was probably mistyped, so the program shows a message asking the user to enter it again. The first 12 digits have a weighted total of 93, so the check digit is 10 - 3 = 7. It equals the entered check digit, so no error is found. Any difference between the two check digits means the number is rejected. The system does not accept it just because most of the digits look right. The check digit is the amount needed to reach the next multiple of 10. 93 + 7 = 100, so the check digit is 7, which matches the ISBN.

Common mistakes: 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. 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".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 179–188) and word search (Modules 168–188).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A user types in an ISBN. What does the system do with the first 12 digits?
Recalculates the check digit from themStores them without any calculation
Matches
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.
Applying
Meanings
Term
recalculate and compare
Meaning
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.
Practice
INPUT isbn
Testing
Gaps
IF calculated entered THEN
Check Answer
Spots
2entered ← LastDigit(code)
3calc ← LastDigit(code)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Ermine' badge — Tundra Streak, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

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
The check digit is worked out again from the other digits so it can be compared with the one the user typed.
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
When the recalculated check digit and the entered check digit match, the number passes the check.
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
Any difference between the two check digits means the number is rejected. The system does not accept it just because most of the digits look 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 ✓
The check digit is the amount needed to reach the next multiple of 10. 93 + 7 = 100, so the check digit is 7, which matches the ISBN.
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 ✓
Swapping the 4 and the 0 changes the weighted sum, so the recalculated check digit (5) no longer matches the entered one (7).

Match the Pairs

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
IF calc <> entered THEN → Compares the recalculated check digit with the entered one and runs the rejection code if they differ
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"
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
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.
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.

Key Term

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.

Fill in the Blanks

1. calculated ← CalcCheckDigit(first12) IF calculated <> entered THEN OUTPUT "Re-enter the number"
Hint: Type the comparison operator that tests whether the two check digits are different
2. IF calculated <> entered THEN OUTPUT "Re-enter the number" ENDIF
Hint: Type the keyword that displays the message asking the user to try again
3. calculated ← 5 entered ← 7 IF calculated <> entered THEN reject
Hint: Type the variable that holds the check digit typed in by the user, which is compared with the recalculated one
4. IF calculated = entered THEN OUTPUT "Number accepted" ENDIF
Hint: Type the operator that checks the recalculated and entered check digits match, so a valid ISBN is accepted
5. WHILE calculated <> entered DO OUTPUT "Re-enter the number" INPUT entered
Hint: Type the keyword that reads a new value from the user after the number was rejected

Spot the Error

Question 1
A INPUT code
B entered ← LastDigit(code)
C calc ← LastDigit(code)
D IF calc <> entered THEN
E OUTPUT "Re-enter number"
Line 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.
Question 2
A isbn ← "978030640615"
B calc ← CheckDigit(isbn)
C IF calc = LastDigit(isbn) THEN
D OUTPUT "Valid ISBN"
Line 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".
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"
Line 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).
Question 4
A INPUT isbn
B calc ← CheckDigit(isbn)
C entered ← LastDigit(isbn)
D IF calc = entered THEN
E OUTPUT "Number rejected"
F ENDIF
Line 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.
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"
Line 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.

Student with a class code? Join your class →