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

Counting and asking

Week 10 · Unit 4: Be a storyteller · 3 lessons
2

Input, process, output

Computing 5: Unit 4, pp. 44–57
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.

Worked examples
Startask: How many stickers?set stickers to answerset cost to stickers × 3say: Cost: (cost)End
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.
whenclickedaskHow many stickers?and waitsetstickerstoanswersetcosttostickers*3sayjoinCost: costfor3seconds
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
44 × 3 = 12Cost: 12
77 × 3 = 21Cost: 21
00 × 3 = 0Cost: 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) types a number(b) adds 1(c) says the result(d) joins two words
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?
3
Complete the flowchart for a program that asks for a number and says double that number. Write the missing steps.
Startask: Which number?set number to answer??End
4
Why do we store the answer in a variable and not use (answer) again later?