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.
Worked examples
Step
Instruction
1
When the down arrow key is pressed
2
Point in direction 180
3
Move 50 steps
4
Say “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.
Input
Outputs
the down arrow key is pressed
1 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.
Algorithm
Input
Output
reset
the green flag is clicked
costume owl-a, place x: −100, y: 50
hoot
the owl is clicked
the owl says “Hoo!” for 2 seconds
walk
the left arrow key is pressed
the 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.
Step
Instruction
1
When the right arrow key is pressed
2
Start sound Boing
3
Change x by 40
4
Switch costume to goat-b
The input is pressing the right arrow key. The outputs are a Boing sound, a move 40 steps to the right and the costume changing to goat-b.
2
How many outputs does this algorithm have, and what is its input?
Step
Instruction
1
When the green flag is clicked
2
Switch costume to goat-a
3
Go to x: −60, y: 20
Two outputs: the costume changes and the goat moves to x: −60, y: 20. The input is clicking the green flag.
3
Write the algorithm: when a sprite is clicked it says “Hello!” for 2 seconds and plays a Meow sound.
1 When this sprite is clicked. 2 Say “Hello!” for 2 seconds. 3 Start sound Meow.
4
Mia says that the input of this program is the glide. Is she right?
No. The input is pressing the space key. The glide is an output.