GoalWrite an algorithm and a program that asks a question, stores the answer, works something out and shows the result.
New words
input · data that goes into a program, such as an answer typed by the userprocess · the part of a program that works something outoutput · what the program shows or says at the endjoin · to put two pieces of text together to make one
Explanation
Many programs follow three parts: input, process and output. The input is the data that a person gives to the program, for example by typing an answer. The process works something out, for instance by adding or by joining words. The output is what the program shows or says. In Scratch, the block ‘ask and wait’ puts the typed text in the reporter (answer). The answer changes every time that we ask a new question, so we store it in a variable if we want to keep it. Then we use the variable in the process and in the output. Each time the program runs, the variable can hold a different value.
input→process→output
Worked examples
This flowchart shows a sticker shop. Each sticker costs 3 coins. The user types how many stickers they want, the program multiplies by 3, and then it says the cost.
The same program in Scratch. The input is the answer, the process is the multiplication and the output is the say block.
Input (stickers)
Process (stickers × 3)
Output
4
4 × 3 = 12
Cost: 12
7
7 × 3 = 21
Cost: 21
0
0 × 3 = 0
Cost: 0
The variables take different values on each run. The process is the same every time.
Class activity
Human program (3 players). Player 1 is the input: they ask a question such as ‘How many stickers do you want?’ and write the answer on a card. Player 2 is the process: they multiply the number by 3 on paper. Player 3 is the output: they say ‘Cost: …’ aloud. Run it three times with different numbers and fill in a table of input, process and output. Which part changes each time? Which part never changes?
Practice
1
Write input, process or output: (a) the user types a number, (b) the program adds 1, (c) the sprite says the result, (d) the program joins two words.
(a) input. (b) process. (c) output. (d) process.
2
Trace the sticker program from the lesson (each sticker costs 3 coins). What does the sprite say if the user types 6? What if the user types 10?
6 × 3 = 18, so it says ‘Cost: 18’. 10 × 3 = 30, so it says ‘Cost: 30’.
3
Complete the flowchart for a program that asks for a number and says double that number. Write the missing steps.
The process step is ‘set double to number × 2’. The output step is ‘say double’.
4
Why do we store the answer in a variable and not use (answer) again later?
The reporter (answer) changes each time the program asks a new question. A variable keeps the old value for as long as we need it.