INPUT and OUTPUT statements

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

INPUT and OUTPUT statements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line stores a value typed by the user in the variable Number?
A INPUT Number
B OUTPUT Number
2. Which line displays the message Total is followed by the value of Total?
A OUTPUT "Total is ", Total
B INPUT "Total is ", Total
3. Which is the correct way to show several items in one OUTPUT statement?
A OUTPUT "Score: " Score " points"
B OUTPUT "Score: ", Score, " points"
4. A program should ask the user for their age and then store it. Which order is best?
A OUTPUT "Enter your age" then INPUT Age
B INPUT Age then OUTPUT "Enter your age"
5. What does the statement INPUT Number do when the program runs?
A It displays the value of Number on the screen
B It waits for the user to type a value and stores it in Number

Match the Pairs

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

Left columnRight column
1INPUT Number AWaits for the user to type a value and stores it in the variable Number
2OUTPUT "Total is ", Total BINPUT must be followed by a variable name, not a message. Use OUTPUT for the message, then INPUT Number to store the value.
3Prompt the user with OUTPUT before asking for a value with INPUT COUTPUT "Enter a number" INPUT Number
4Display several items on one line by separating them with commas DThe items are not separated by a comma. It should be OUTPUT "Total is ", Total.
5INPUT "Enter a number" EDisplays the message Total is followed by the value stored in Total
6OUTPUT "Total is " Total FOUTPUT "Average is ", Average

Definitions

INPUT and OUTPUT

Fill in the Blanks

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

1.
______ "Total is ", Total
2.
_____ Number
3.
OUTPUT "Enter a number" INPUT ______ OUTPUT "You typed ", Number
4.
INPUT Price OUTPUT "Price is ", _____
5.
______ "Enter your age" INPUT Age

Spot the Error

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

Question 1
A DECLARE Number : INTEGER
B INPUT 5
C OUTPUT "You typed ", Number
Question 2
A DECLARE Total : INTEGER
B Total <- 10 + 5
C OUTPUT "Total is " Total
Question 3
A OUTPUT Enter your age
B INPUT Age
C OUTPUT "Age is ", Age
Question 4
A OUTPUT "Enter a number"
B INPUT "Num"
C OUTPUT "Double is ", Num * 2
Question 5
A DECLARE Name : STRING
B INPUT Name
C OUTPUT "Hello ", "Name"

Answer Key

INPUT and OUTPUT statements
Section A: Quick Questions
Q1
A — INPUT Number
Q2
A — OUTPUT "Total is ", Total
Q3
B — OUTPUT "Score: ", Score, " points"
Q4
A — OUTPUT "Enter your age" then INPUT Age
Q5
B — It waits for the user to type a value and stores it in Number
Section B: Match the Pairs
Q1
INPUT Number → Waits for the user to type a value and stores it in the variable Number
Q2
OUTPUT "Total is ", Total → Displays the message Total is followed by the value stored in Total
Q3
Prompt the user with OUTPUT before asking for a value with INPUT → OUTPUT "Enter a number" INPUT Number
Q4
Display several items on one line by separating them with commas → OUTPUT "Average is ", Average
Q5
INPUT "Enter a number" → INPUT must be followed by a variable name, not a message. Use OUTPUT for the message, then INPUT Number to store the value.
Q6
OUTPUT "Total is " Total → The items are not separated by a comma. It should be OUTPUT "Total is ", Total.
Section C: Definitions
Q1
INPUT and OUTPUT — INPUT stores a value the user types into a variable. OUTPUT displays a message or value on screen. Show several items by separating them with commas.
Section D: Fill in the Blanks
Q1
OUTPUT "Total is ", Total
Q2
INPUT Number
Q3
OUTPUT "Enter a number" INPUT Number OUTPUT "You typed ", Number
Q4
INPUT Price OUTPUT "Price is ", Price
Q5
OUTPUT "Enter your age" INPUT Age
Section E: Spot the Error
Q1
B — INPUT must be followed by a variable name that will store the typed value. You cannot input into the value 5. It should be INPUT Number.
Q2
C — When OUTPUT shows several items, they must be separated by commas. A comma is missing after the message. It should be OUTPUT "Total is ", Total.
Q3
A — A message to display must be written in double quotes. Without them the words look like variable names. It should be OUTPUT "Enter your age".
Q4
B — The variable name after INPUT must not be in quotes. Quotes make it a piece of text, not a variable that can store the value. It should be INPUT Num.
Q5
C — Putting Name in quotes outputs the word Name, not the value the user typed. A variable must be written without quotes: OUTPUT "Hello ", Name.