Writing literals in pseudocode

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

Writing literals in pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is the correct way to write the single character Y as a CHAR literal in pseudocode?
A 'Y'
B "Y"
2. Which is the correct way to write the word Yes as a STRING literal?
A 'Yes'
B "Yes"
3. Which is a correct empty STRING literal?
A ''
B ""
4. Which is the correct way to write the REAL number four?
A 4.0
B 4.
5. Which is a correct REAL literal for half?
A 0.5
B .5

Match the Pairs

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

Left columnRight column
1'Y' AIsValid ← TRUE
2"" BAn empty STRING literal: double quotes with nothing between them
3A REAL literal needs a digit on both sides of the decimal point CPrice ← 4.0
4A BOOLEAN literal is TRUE or FALSE, written in capitals DA CHAR literal must use single quotes, not double quotes. Double quotes make it a STRING. It should be 'A'.
5Grade ← "A" (Grade is a CHAR) EA REAL literal needs a digit after the decimal point. 4. should be written as 4.0.
6Total ← 4. FA CHAR literal: one character inside single quotes

Definitions

'Y' "Yes" 4.0 TRUE

Fill in the Blanks

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

1.
DECLARE Grade : ____ // Store the letter A Grade ← 'A'
2.
DECLARE Name : ______ // Start with no text at all Name ← ""
3.
DECLARE Price : REAL // The price is exactly four Price ← ___
4.
DECLARE Found : BOOLEAN // Nothing has been found yet Found ← _____
5.
DECLARE Temp : INTEGER // Three degrees below zero Temp ← __

Spot the Error

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

Question 1
A Name ← 'Sam'
B Age ← 15
C OUTPUT Name, Age
Question 2
A DECLARE Total : REAL
B Qty ← 3
C Total ← Qty * 4.
D OUTPUT Total
Question 3
A DECLARE Found : BOOLEAN
B DECLARE Count : INTEGER
C Count ← 0
D Found ← false
E OUTPUT Found
Question 4
A DECLARE Initial : CHAR
B DECLARE Name : STRING
C Name ← "Maya"
D Initial ← "M"
Question 5
A Temp ← .5
B OUTPUT Temp
C Temp ← Temp + 1.0

Answer Key

Writing literals in pseudocode
Section A: Quick Questions
Q1
A — 'Y'
Q2
B — "Yes"
Q3
B — ""
Q4
A — 4.0
Q5
A — 0.5
Section B: Match the Pairs
Q1
'Y' → A CHAR literal: one character inside single quotes
Q2
"" → An empty STRING literal: double quotes with nothing between them
Q3
A REAL literal needs a digit on both sides of the decimal point → Price ← 4.0
Q4
A BOOLEAN literal is TRUE or FALSE, written in capitals → IsValid ← TRUE
Q5
Grade ← "A" (Grade is a CHAR) → A CHAR literal must use single quotes, not double quotes. Double quotes make it a STRING. It should be 'A'.
Q6
Total ← 4. → A REAL literal needs a digit after the decimal point. 4. should be written as 4.0.
Section C: Definitions
Q1
'Y' "Yes" 4.0 TRUE — Literals have fixed forms: CHAR in single quotes, STRING in double quotes, REAL with a digit each side of the point, BOOLEAN as TRUE or FALSE in capitals.
Section D: Fill in the Blanks
Q1
DECLARE Grade : CHAR // Store the letter A Grade ← 'A'
Q2
DECLARE Name : STRING // Start with no text at all Name ← ""
Q3
DECLARE Price : REAL // The price is exactly four Price ← 4.0
Q4
DECLARE Found : BOOLEAN // Nothing has been found yet Found ← FALSE
Q5
DECLARE Temp : INTEGER // Three degrees below zero Temp ← -3
Section E: Spot the Error
Q1
A — A STRING literal must be in double quotes. Single quotes are only for one CHAR. It should be Name ← "Sam".
Q2
C — A REAL literal needs a digit on both sides of the decimal point. 4. is wrong and should be 4.0.
Q3
D — BOOLEAN values are written in capitals as TRUE or FALSE. It should be Found ← FALSE.
Q4
D — Initial is a CHAR, so its literal goes in single quotes. Double quotes make it a STRING. It should be Initial ← 'M'.
Q5
A — A REAL literal needs a digit before the decimal point as well as after it. It should be Temp ← 0.5.