13 digit product codes: Weighted sum of digits (entered one at a time)

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, entering each digit one at a time. Then adds up all the digits, every second one multiplied by 3 (2nd, 4th, and so on), and shows the total as the output.

Testing examples:

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

Input Output
9
4
2
1
9
0
2
8
1
4
7
9
2
Total: 110

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
whenclickedsayjoinTotal: total
repeat6
askjoinjoinEnter digit index of the product code:andwaitaskjoinjoinEnter digit index of the product code:andwaitaskjoinjoinEnter digit index of the product code:andwait
changetotal 1byanswersettotaltototal1+total2*3changeindexby1changetotal 1byanswerchangeindexby1changetotal 2byanswersettotal 1to0settotal 2to0setindexto1
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 output is the sum of total 2 multiplied by 3 and total 1.

Show Scratch solution