AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Inputs and outputs

Week 28 · Unit 12: Be a problem solver · 3 lessons
3

Start and reset algorithms

Computing 3: Unit 12, pp. 178–193
GoalWrite linear algorithms for a sprite, with an input and an output, including one that resets the sprite.
New words
linear algorithm · an algorithm whose steps run one after the other in a straight linereset · to put something back to how it was at the startstart position · the place where a sprite begins
Explanation

A linear algorithm is a list of steps that run one after the other, from top to bottom. For a sprite, the first line says what starts the algorithm. That is the input: clicking the green flag, clicking the sprite or pressing a key. The lines after it are the outputs: what the sprite does. A reset algorithm puts the sprite back in its start position and costume. It starts with the green flag, so that every new game begins in the same way. A second algorithm makes the sprite do its job. Each job gets its own algorithm.

Worked examples
LineTurtle reset algorithm
inputWhen the green flag is clicked
output 1switch costume to turtle-a
output 2go to x: −150, y: −60
This is the reset algorithm for a turtle. The input is clicking the green flag. There are two outputs: the turtle changes to its first costume and goes to its start position.
LineTurtle move algorithm
inputWhen the space key is pressed
output 1glide 2 seconds to x: 100, y: −60
output 2say “Made it!” for 2 seconds
This is the move algorithm for the turtle. The input is pressing the space key. The outputs are that the turtle glides to the right and says something.
What we doWhere the turtle ends
green flag, then spacex: 100
space again, with no resetx: 100 (it did not move)
green flag, then spacex: 100 (it moved again)
Why do we need the reset algorithm? Press the space key once and the turtle glides from x: −150 to x: 100. Press it again and the turtle is already at x: 100, so it does not move. After the green flag, the turtle is back at the start, and the glide works again.
Class activity

Reset and go (in pairs): mark a start spot on the floor with a piece of paper. One of you is the sprite. The other says “green flag” and the sprite goes back to the start spot and faces the wall. When the other says “space”, the sprite walks 4 steps forward and says “Made it!”. Say “space” twice without a green flag. What happens to the second walk? Then say “green flag” and “space” again. Talk about why a reset is useful.

Practice
1
Dina writes a reset algorithm for a duck, but it starts when the duck is clicked. Why is that a problem?
LineDuck reset algorithm
inputWhen this sprite is clicked
output 1switch costume to duck-a
output 2go to x: 80, y: 20
2
Write the algorithm for the duck’s second job. The input is pressing the up arrow key. The outputs are that the duck glides 1 second to x: 80, y: 120 and says “Quack!” for 1 second.
3
Name the input and the outputs of this algorithm.
StepInstruction
1When this sprite is clicked
2Change size by 20
3Start sound Pop
4
Why does a program often have a reset algorithm that starts with the green flag?