Outputting several values with commas

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

Outputting several values with commas

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which OUTPUT command displays: You have 3 lives left (Lives holds 3)?
A OUTPUT "You have ", Lives, " lives left"
B OUTPUT "You have " Lives " lives left"
2. Lives is 3. What does OUTPUT "You have ", Lives, " lives left" display?
A You have Lives lives left
B You have 3 lives left
3. Which command puts the space between the word Score: and the number in Score: 50 (Score holds 50)?
A OUTPUT "Score: ", Score
B OUTPUT "Score:", Score
4. Name holds "Sam". What does OUTPUT "Hello", Name display?
A HelloSam
B Hello Sam
5. Which is the correct way to display the text and the variable Total together?
A OUTPUT "Total = Total"
B OUTPUT "Total = ", Total

Match the Pairs

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

Left columnRight column
1OUTPUT "You have ", Lives, " lives left" AThe commas between the values are missing. Each value in an OUTPUT must be separated by a comma.
2OUTPUT "Score: ", Score BOUTPUT "Hello ", Name, "!"
3Spaces you want displayed must be placed inside the quotes of the text CDisplays the words Score: followed by the value stored in the variable Score
4Text and variables can be mixed in one OUTPUT, with commas between each value DThere is no space inside the quotes after the colon, so the output shows Score:10 with no gap.
5OUTPUT "You have " Lives " lives left" EOUTPUT "Name: ", Name
6OUTPUT "Score:", Score FDisplays text, then the value of Lives, then more text, all on one line

Definitions

OUTPUT "You have ", Lives, " lives left"

Fill in the Blanks

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

1.
______ "You have ", Lives, " lives left"
2.
Lives ← 3 OUTPUT "You have ", _____, " lives left"
3.
_____ ← 25 OUTPUT "Coins: ", Coins, " gold"
4.
Lives _ 3 OUTPUT "You have ", Lives, " lives left"
5.
DECLARE Lives : _______ Lives ← 3 OUTPUT "Lives: ", Lives

Spot the Error

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

Question 1
A OUTPUT "Level " 1
B Score ← 0
C OUTPUT "Score ", Score
Question 2
A Lives ← 3
B OUTPUT "You have ", "Lives"
C Lives ← Lives - 1
Question 3
A DECLARE Lives : INTEGER
B Lives ← 3
C Lives ← Lives - 1
D OUTPUT "Now", Lives, " left"
Question 4
A Score ← 10
B OUTPUT "Score: "; Score
C OUTPUT "Done"
Question 5
A Name ← "Sam"
B Age ← 15
C OUTPUT Name, " is ", Age,

Answer Key

Outputting several values with commas
Section A: Quick Questions
Q1
A — OUTPUT "You have ", Lives, " lives left"
Q2
B — You have 3 lives left
Q3
A — OUTPUT "Score: ", Score
Q4
A — HelloSam
Q5
B — OUTPUT "Total = ", Total
Section B: Match the Pairs
Q1
OUTPUT "You have ", Lives, " lives left" → Displays text, then the value of Lives, then more text, all on one line
Q2
OUTPUT "Score: ", Score → Displays the words Score: followed by the value stored in the variable Score
Q3
Spaces you want displayed must be placed inside the quotes of the text → OUTPUT "Name: ", Name
Q4
Text and variables can be mixed in one OUTPUT, with commas between each value → OUTPUT "Hello ", Name, "!"
Q5
OUTPUT "You have " Lives " lives left" → The commas between the values are missing. Each value in an OUTPUT must be separated by a comma.
Q6
OUTPUT "Score:", Score → There is no space inside the quotes after the colon, so the output shows Score:10 with no gap.
Section C: Definitions
Q1
OUTPUT "You have ", Lives, " lives left" — One OUTPUT command can display several values, separated by commas. Mix text in quotes with variables. Any spaces you want shown must be inside the quotes.
Section D: Fill in the Blanks
Q1
OUTPUT "You have ", Lives, " lives left"
Q2
Lives ← 3 OUTPUT "You have ", Lives, " lives left"
Q3
Coins ← 25 OUTPUT "Coins: ", Coins, " gold"
Q4
Lives ← 3 OUTPUT "You have ", Lives, " lives left"
Q5
DECLARE Lives : INTEGER Lives ← 3 OUTPUT "Lives: ", Lives
Section E: Spot the Error
Q1
A — The values in an OUTPUT command must be separated by commas. A comma is missing between "Level " and 1. It should be OUTPUT "Level ", 1.
Q2
B — Quotes around Lives make it text, so the word Lives is displayed instead of its value. A variable must be written without quotes: OUTPUT "You have ", Lives.
Q3
D — Spaces must be inside the quotes. Without a space after Now, the output runs together as Now2 left. It should be "Now ".
Q4
B — OUTPUT values are separated by commas, not semicolons. It should be OUTPUT "Score: ", Score.
Q5
C — Commas go between values only. A trailing comma after the last value is an error because nothing follows it. It should be OUTPUT Name, " is ", Age.