Programming for Children
Primary 6 · Science and Elementary Technology
Programming for Children
Lesson 3 of 6
30 min
Let's begin
Mutesi helps her mother sell avocados at the market. Every evening they count how many avocados were sold and work out the money. "Could the school laptop do these sums for us?" Mutesi wonders. Yes, it can! Today you will use Scratch to add, subtract, multiply, divide and find averages.
Scratch is a free programming language made at MIT for children. Instead of typing code, you drag coloured blocks and snap them together. Look at the picture below and find these parts:

The green Operators category holds the maths blocks. Scratch uses * for multiply and / for divide.
| What you want | Scratch block | Example | Result |
|---|---|---|---|
| Sum | ( ) + ( ) | (25) + (17) | 42 |
| Difference | ( ) - ( ) | (50) - (18) | 32 |
| Product | ( ) * ( ) | (6) × (7) | 42 |
| Quotient | ( ) / ( ) | (20) / (8) | 2.5 |
| Average of three numbers | (( ) + ( ) + ( )) / (3) | ((12 + 15) + 18) / 3 | 15 |
The round operator blocks fit into the holes of other blocks. For example, say (6 × 7) makes the sprite say 42. When you put one round block inside another, Scratch works out the inside block first, just like brackets in maths. For the average, the inside block adds the marks (12 + 15 + 18 = 45), then the outside block divides by 3 (45 ÷ 3 = 15).
Note: Scratch's divide block gives decimals, so 17 / 5 gives 3.4. If you want the remainder instead, the mod block gives it: 17 mod 5 = 2.
The Sensing block ask [ ] and wait shows a question and a box to type in. Whatever the user types is kept in the round answer block. We keep answers in variables, which are named boxes for storing numbers (you will learn more in Lesson 5).
when green flag clicked
ask [How many avocados did you sell?] and wait
set [avocados] to (answer)
ask [What is the price of one avocado in Frw?] and wait
set [price] to (answer)
say (join [Total money in Frw: ] ((avocados) * (price))) for 3 seconds
If Mutesi types 24 and 200, the sprite says "Total money in Frw: 4800", because 24 × 200 = 4,800.
The Raspberry Pi project Brain game builds a quiz. The sprite sets two variables to a pick random 2 to 12 number, asks their product, then uses if (answer) = (number 1 * number 2) then say "yes!" else say "nope". Try building it yourself!
Turtle Blocks has the same + − × ÷ blocks in its Number palette, and a print block that shows a result. You can even put 360 ÷ 6 straight into a right block, and the computer works out the angle for you.
Tip
Build maths from the inside out. The block deepest inside is worked out first, just like the brackets in ((12 + 15) + 18) ÷ 3.
Answers
What you learned today
Sources and credits
The exercises (Try it yourself and the practice questions) are written by Ganzaa. Scratch is a free project of the Scratch Foundation, at scratch.mit.edu.
This lesson adapts CC BY-SA material and is shared under CC BY-SA 4.0.
Quick check