# 13 digit product codes: Check if total is a multiple of 10 (one line of input)

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

## Requirement:

Write a program that asks the user to enter a 13 digit product code, all in one line of input. Then adds up all the digits, every second one multiplied by 3 (2nd, 4th, and so on) and show if this total is a multiple of 10 (valid product code). For this challenge make sure the user can only enter a 13 digit product code.

## Testing examples:

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

Input Output
9418870000852 Valid product code!
9415277000126 Valid product code!
9300728854542 Invalid product code!
9328350003719 Valid product code!
9415377000126 Invalid product code!
9418770000852 Invalid product code!

## 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 a 13-digit product code:] and wait
say [Please enter a 13 digit number!]

say [Invalid product code!]

say [Valid product code!]
repeat (6)
end

if <((total) mod (10)) = [0]> then
else
end

if <(length of (product code)) = [13]> then
else

end
set [index v] to [1]

set [product code v] to []

set [total 1 v] to [0]

set [total 2 v] to [0]

set [total v] to [0]

set [total 1 v] to ((total 1) + (letter (index) of (product code)))

set [total v] to ((total 1) + ((total 2) * (3)))

set [total 1 v] to ((total 1) + (letter (index) of (product code)))

change [index v] by (1)

set [total 2 v] to ((total 2) + (letter (index) of (product code)))

change [index v] by (1)

change [product code v] by (answer)
Hints
• You can find the number digits in a number by using the length of () block unders “Operators”. For example: length of (2938339392383) //13

• You can access a letter (or a digit) at a specified position in a string (or number) by using the letter () of [] block under “Operators”. For example: letter (4) of [18392819202910] //9

• In this challenge you need to access all the digits of the product code number entered, adding the 1st, 3rd, 5th and so on digits and storing the result in variable "total 1" and adding the 2nd, 4th, 6th and so on digits and storing the result in variable "total 2". The output displays if the sum of "total 2" multiplied by 3 and "total 1" is a multiple of 10 or not.