ConceptsAll the ideas

Rule Machines

Idea 22of 23Builds onReuse code for a new job

Write code for a savings plan

How do you turn a money story into code?

Today you'll discover

  • which story number goes on which line
  • how to check your code
  • what the code shows

Think firstMaya has $8 and saves $6 a week for 5 weeks

Which code models Maya's savings?

Decide first, then press Next. Find the start, the change and how many times.

Code with its lines hidden, then shown: SET 8, REPEAT 5 TIMES, ADD 6, END, OUTPUT. Bars for Maya's money from $8 at the start to $14, $20, $26, $32 and $38 after weeks 1 to 5, each marked plus 6, and the working $8 + 5 × $6 = $38. The last step asks what the seedling code, SET 4 and five passes of ADD 3, outputs.

See the whole ideathe big idea and the key word, in one place

The big idea

To model a story in code: start in SET, count in REPEAT, change inside the loop.

Maya's codeSET 8 (what she has), REPEAT 5 TIMES (the weeks), ADD 6 (what she saves each week), END, OUTPUT.

Back to expressionsIt is the same rule as 6x + 8: the change goes with the number of weeks, and the start is added once.

Key word

model
code, a drawing or an expression that acts out a real situation with numbers

Ready to use it?

  • Write a loop that models a savings or growing story.
Practise this idea