Calculate the last digit of an ISBN-10 number

Challenge Level: Ready to expand

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks the user to enter the first 9 digits of an ISBN-10 number as the input and says what the last digit should be.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided:

Input Output
020153082 The last digit is: 1
014003219 The last digit is: 3
052135741 The last digit is: 1
043942089 The last digit is: X

Languages

Scratch

What it should look like

Click on the green flag, enter the inputs provided in the “testing examples” to see the expected output of your program.

Recommended blocks
when green flag clicked

ask [Enter the first 9 digits of an ISBN-10 number:] and wait
say [The last digit is: X]

say (join [The last digit is: ] (last digit))
set [index v] to [1]

set [multiplier v] to [10]

set [first 9 digits v] to [0]

set [total v] to [0]

set [last digit v] to [0]

set [first 9 digits v] to (answer)

change [total v] by ((multiplier) * (letter (index) of (first 9 digits)))

change [index v] by (1)

change [multiplier v] by (-1)

set [last digit v] to (((0) - (total)) mod (11))
if <(last digit) = [10]> then
else
end

repeat (9)
end
Hints
  • Calculate the sum of all the 9 digits each multiplied by its (integer) weight, descending from 10 to 2. The last digit (check digit) is calculated by subtracting the final total from 0 mod 11.

  • If the last digit is the number 10, replace it with the letter ‘X’.

    For example the last digit of the ISBN-10 “020153082” is calculated by:

    So the last digit is 1 (i.e. (0-98) mod 11 which is equal to 1).

    Another example: The last digit of the ISBN-10 “043942089” is calculated by:

    So the last digit is ‘X’ (i.e. (0-199) mod 11 which is equal to 10).

Show Scratch solution