Input and output in an algorithm

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Input and output in an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which step is an INPUT step?
A ASK the user for their name
B SHOW the message on the screen
2. Which step is an OUTPUT step?
A ASK "What is your name?" and store it in name
B SHOW "Hello!"
3. What happens to the answer when an algorithm ASKs for a name?
A It is stored in a variable
B It is shown on the screen straight away
4. Which algorithm greets the user by the name they typed?
A 1. SHOW "Hello " and name 2. ASK "Your name?" and store in name
B 1. ASK "Your name?" and store in name 2. SHOW "Hello " and name
5. Which step uses the stored answer in a later step?
A SHOW "Nice to meet you, " and name
B ASK "What is your name?"

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1ASK "What is your name?" and store in name ASHOW comes before ASK, so the variable name has no value yet. ASK must come first so the answer is stored before it is shown.
2SHOW "Welcome to the game!" BSHOW "Hello, " and name
3Using the stored answer in a later step, so the message includes the user's name CASK was used to display a message, but ASK is for input. SHOW should be used to display a message.
4An input step asks the user for a value and stores it in a variable DAn input step: it asks the user for their name and keeps the answer in the variable called name
51. SHOW name 2. ASK "What is your name?" and store in name EAn output step: it displays a message on the screen for the user to read
6ASK "Hello, " and name FASK "What is your favourite colour?" and store in colour

Definitions

ASK and SHOW

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
name ← ___ "What is your name?"
2.
name ← ASK "What is your name?" ____ "Hello, " + name
3.
name ← ASK "What is your name?" SHOW "Hello, " + ____
4.
____ ← ASK "What is your name?" SHOW "Nice to meet you, " + name
5.
name _ ASK "What is your name?" SHOW "Welcome, " + name

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A SHOW "Your name?" INTO name
B SHOW "Hello, " + name
C SHOW "Nice to meet you!"
Question 2
A SHOW "Welcome!"
B ASK "Your name?" INTO name
C SHOW "Hi, " + name
D SHOW "Enjoy the quiz, " + nam
Question 3
A ASK "Your name? INTO name
B SHOW "Hello, " + name
C SHOW "Welcome to the game!"
Question 4
A ASK "Your name?" INTO name
B ASK "Your age?" INTO age
C SHOW "name" + " is " + age
Question 5
A SHOW "Welcome to Cloodit!"
B ASK "Pet name?" INTO pet
C ASK "Your pet is " + pet

Answer Key

Input and output in an algorithm
Section A: Quick Questions
Q1
A — ASK the user for their name
Q2
B — SHOW "Hello!"
Q3
A — It is stored in a variable
Q4
B — 1. ASK "Your name?" and store in name 2. SHOW "Hello " and name
Q5
A — SHOW "Nice to meet you, " and name
Section B: Match the Pairs
Q1
ASK "What is your name?" and store in name → An input step: it asks the user for their name and keeps the answer in the variable called name
Q2
SHOW "Welcome to the game!" → An output step: it displays a message on the screen for the user to read
Q3
Using the stored answer in a later step, so the message includes the user's name → SHOW "Hello, " and name
Q4
An input step asks the user for a value and stores it in a variable → ASK "What is your favourite colour?" and store in colour
Q5
1. SHOW name 2. ASK "What is your name?" and store in name → SHOW comes before ASK, so the variable name has no value yet. ASK must come first so the answer is stored before it is shown.
Q6
ASK "Hello, " and name → ASK was used to display a message, but ASK is for input. SHOW should be used to display a message.
Section C: Definitions
Q1
ASK and SHOW — ASK is an input step: it asks the user for a value and stores it in a variable. SHOW is an output step: it displays a result, like a message, on the screen.
Section D: Fill in the Blanks
Q1
name ← ASK "What is your name?"
Q2
name ← ASK "What is your name?" SHOW "Hello, " + name
Q3
name ← ASK "What is your name?" SHOW "Hello, " + name
Q4
name ← ASK "What is your name?" SHOW "Nice to meet you, " + name
Q5
name ← ASK "What is your name?" SHOW "Welcome, " + name
Section E: Spot the Error
Q1
A — SHOW is an output step and only displays things. To ask the user for a value and store it in name, line 1 should start with ASK.
Q2
D — The answer was stored in a variable called name, but this line uses nam. The variable name must match exactly, so it should be + name.
Q3
A — The question text is missing its closing quote mark. It should be ASK "Your name?" INTO name.
Q4
C — Putting name in quotes shows the word name instead of the stored answer. To use the stored value, write name without quotes.
Q5
C — ASK is an input step that waits for the user to type an answer. To display a message on the screen, use SHOW.