# Check for valid ISBN-10 number

Learning outcomes

Students will be able to:

## Requirement:

Write a program that asks the user to enter an ISBN-10 number as an input and says if the ISBN-10 number is valid or not. The last digit of the ISBN-10 must range from 0 to 10 (the symbol X is used for 10).

## Testing examples:

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

Input Output
0201530821 This is a valid ISBN-10 number!
0140032193 This is a valid ISBN-10 number!
0521357411 This is a valid ISBN-10 number!
043942089X This is a valid ISBN-10 number!
0201540821 This is an invalid ISBN-10 number!
0240032193 This is an invalid ISBN-10 number!
0521357511 This is an invalid ISBN-10 number!
0439420896 This is an invalid ISBN-10 number!

## 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 an ISBN-10 number:] and wait
say [This is a valid ISBN-10 number!]

say [This is an invalid ISBN-10 number!]
change [total v] by ((multiplier) * (letter (index) of (ISBN-10 number)))

change [multiplier v] by (-1)

change [index v] by (1)

set [index v] to [1]

set [multiplier v] to [10]

set [total v] to [0]

change [total v] by ((multiplier) * (10))

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

repeat (10)
end

if <<(index) = [10]> and <(letter (index) of (ISBN-10 number)) = [X]>> then
else
end
Hints
• To check if an ISBN-10 number is valid, the sum of all the ten digits each multiplied by its (integer) weight, descending from 10 to 1, needs to be a multiple of 11 (i.e. total mod 11 is equal to 0).

• If the last digit of an ISBN-10 is X, you need to multiply 10 by its integer weight 1 (as it’s the last digit) to calculate the total.

For example for an ISBN-10 of 0201530821:

This is a valid ISBN-10 as 99 mod 11 is 0.