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

Code the algorithm

Week 29 · Unit 12: Be a problem solver · 3 lessons
2

Name inputs and outputs

Computing 3: Unit 12, pp. 178–193
GoalRead an algorithm and name its input and its outputs.
New words
event · something that happens, such as a click or a key press, which starts a scriptoutput · what the sprite does after the eventkey press · pressing a key on the keyboard, which can be the input that starts a script
Explanation

Every algorithm for a sprite has an input and outputs. The input is the first step. It is the event that starts the algorithm: the green flag, a click on the sprite, or a key press. The outputs are the things that the sprite does after that. A sprite can move, change costume, play a sound or say something. To find the outputs, read each step after the first and list what changes: the place, the look, the sound or the words. A table with two columns, input and outputs, helps us to keep track.

input: the down arrow keyoutputs: turn, move, speak
Worked examples
StepInstruction
1When the down arrow key is pressed
2Point in direction 180
3Move 50 steps
4Say “Found it!” for 1 second
Here is the owl’s down-arrow algorithm. The input is pressing the down arrow key. There are three outputs: the owl turns to face down, moves 50 steps and speaks.
InputOutputs
the down arrow key is pressed1 the owl turns to face down
2 the owl moves 50 steps down
3 the owl says “Found it!” for 1 second
Here is the answer table for the owl’s algorithm. We listed each output on its own line.
AlgorithmInputOutput
resetthe green flag is clickedcostume owl-a, place x: −100, y: 50
hootthe owl is clickedthe owl says “Hoo!” for 2 seconds
walkthe left arrow key is pressedthe owl changes x by −30
One sprite can have several algorithms, each with its own input. The first one resets the owl. The second needs a click. The third needs a key.
Class activity

Input-output detectives (in pairs): write four short algorithms for a sprite, each on its own card, such as “When the sprite is clicked: say Hello for 2 seconds.” Your partner puts a coloured counter on the input and counters of another colour on the outputs. Swap and check each other’s cards. Did you find the same inputs and outputs?

Practice
1
Name the input and the outputs of this algorithm.
StepInstruction
1When the right arrow key is pressed
2Start sound Boing
3Change x by 40
4Switch costume to goat-b
2
How many outputs does this algorithm have, and what is its input?
StepInstruction
1When the green flag is clicked
2Switch costume to goat-a
3Go to x: −60, y: 20
3
Write the algorithm: when a sprite is clicked it says “Hello!” for 2 seconds and plays a Meow sound.
4
Mia says that the input of this program is the glide. Is she right?
whenspacekey pressedglide1secs to x:60y:0