GoalWrite INPUT and OUTPUT statements, use double quotation marks correctly and join items with a comma.
New words
INPUT · a command that stores what the user types in a variableOUTPUT · a command that shows data on the screenstring · text in double quotation marks, shown exactly as writtenconcatenation · joining two or more items to make one longer piece of text
Explanation
INPUT takes what the user types and stores it in a variable, so it always needs an identifier, for example INPUT name. OUTPUT shows data on the screen. Text that must appear exactly as written is a string, and it goes inside double quotation marks. Without the quotation marks, the computer reads the word as the identifier of a variable and shows the value stored in it. To show text and variables together you join them. Joining is called concatenation, and in our house style a comma does it. The comma adds nothing between the items, so put any spaces inside the quotation marks. Other styles use + or &, and both are valid too. In the picture the user types Nodira.
Pseudocode
1INPUT reader
2OUTPUT "Welcome, ", reader, "!"
Output
Welcome, Nodira!
Worked examples
Statement
Shown on the screen
OUTPUT team
Eagles
OUTPUT "team"
team
OUTPUT "Team: ", team
Team: Eagles
OUTPUT team, team
EaglesEagles
Quotation marks decide what is shown. Here the variable team holds the text Eagles. The same word gives different output with and without quotation marks.
Pseudocode
1shelf ← "B"2number ← "27"3OUTPUT shelf, number
Output
B27
Concatenation joins strings into one. Two variables hold the strings B and 27, the shelf and the place of a library book. The comma puts them side by side with no gap, so the output is the code B27.
Pseudocode
1OUTPUT "Enter the book code:"2INPUT code
3OUTPUT "Enter the reader's name:"4INPUT reader
5OUTPUT reader, " has borrowed book ", code
Output
Enter the book code:
Enter the reader's name:
Kenji has borrowed book B27
A longer algorithm for a school library desk. The user types B27 and then Kenji. Notice that the spaces are inside the quotation marks.
Class activity
Colour hunt (no computer). Copy the four-line algorithm below onto paper. Use four colours: circle the command words in one colour, the variable identifiers in a second, the strings in a third and the commas that join items in a fourth. Algorithm: OUTPUT "Name of your stall?" / INPUT stall / OUTPUT "How many apples?" / INPUT apples / OUTPUT stall, " has ", apples, " apples". Compare with a partner. Then extend it with two lines that ask for the number of pears, and one line that shows it. If you have a computer or tablet, write the same program in Python.
Practice
1
The user types mango and then 3. Write what the algorithm shows on the screen.
Pseudocode
1INPUT fruit
2INPUT kilos
3OUTPUT "You chose ", fruit
4OUTPUT kilos, " kg"
You chose mango, then on a new line 3 kg. The words in quotation marks are shown exactly, and the variables are replaced by their values.
2
This algorithm has two mistakes. Find them and write the corrected version.
Pseudocode
1OUTPUT "How many tickets?"2INPUT
3OUTPUT You bought, tickets
Line 2: INPUT has no variable, so write INPUT tickets. Line 3: You bought is text, so it needs quotation marks: OUTPUT "You bought ", tickets. The variable tickets is then used correctly.
3
Write pseudocode that asks for a team colour and a number of goals and then shows a sentence such as Team blue scored 4 goals.
OUTPUT "Team colour?" / INPUT colour / OUTPUT "Goals?" / INPUT goals / OUTPUT "Team ", colour, " scored ", goals, " goals". Any valid wording that gives the same sentence is correct.
4
The variable total holds 45. Explain the difference between OUTPUT "total" and OUTPUT total.
OUTPUT "total" shows the word total, because it is a string in quotation marks. OUTPUT total shows 45, the value stored in the variable.