# 13 digit product codes: Calculate the last digit (entered one digit at a time)

Challenge Level: Ready to expand

Learning outcomes

Students will be able to:

## Requirement:

Write a program that asks the user to enter the first 12 digits of a 13 digit product code, one at a time, and works out the last digit as the output.

## Testing examples:

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

Input Output
9
3
2
8
3
5
0
0
0
3
7
1
The last digit is: 9
9
3
0
0
7
2
8
8
5
4
5
4
The last digit is: 3
9
4
1
4
2
2
6
1
0
0
8
4
The last digit is: 9

## 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

say (join [The last digit of the product code is ] (last digit))

repeat (6)
end
ask (join (join [Enter digit ] (index)) [ of the product code:]) and wait

ask (join (join [Enter digit ] (index)) [ of the product code:]) and wait
set [odd total v] to [0]

set [even total v] to [0]

set [index v] to [1]

set [last digit v] to [0]

change [index v] by (1)

change [odd total v] by (answer)

change [index v] by (1)

change [even total v] by (answer)

set [last digit v] to (((0) - ((odd total) + ((even total) * (3)))) mod (10))
Hints
• You need to add up 1st, 3rd, 5th and so on digits and store the result in a variable called "total 1". Then add up 2nd, 4th, 6th and so on digits and store the result in variable called "total 2". The last digit (check digit) is then calculated by subtracting the sum of "total 2" multiplied by 3, and "total 1" from 0 mod 10.