BOOLEAN data type

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

BOOLEAN data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which declaration correctly creates a variable that stores yes/no information?
A DECLARE GameOver : YESNO
B DECLARE GameOver : BOOLEAN
2. How many different values can a BOOLEAN variable hold?
A Two: TRUE and FALSE
B Any whole number
3. Which line assigns a BOOLEAN value correctly?
A GameOver ← TRUE
B GameOver ← "TRUE"
4. Which statement about TRUE and FALSE is correct?
A They must always be written in quotes
B They are keywords, not strings
5. Which piece of information is best stored in a BOOLEAN variable?
A Whether the player has won (yes or no)
B The player's full name

Match the Pairs

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

Left columnRight column
1DECLARE GameOver : BOOLEAN ATRUE is in quotes, so it is a STRING and not a BOOLEAN value. It should be GameOver ← TRUE
2GameOver ← TRUE BDECLARE LevelComplete : BOOLEAN
3A BOOLEAN variable can hold yes/no information, such as whether a player has finished the level CYES is not a BOOLEAN value. A BOOLEAN can only be TRUE or FALSE, so use GameOver ← TRUE
4TRUE and FALSE are keywords, so they are written without quotes when assigned DCreates a variable called GameOver that can only store TRUE or FALSE
5GameOver ← "TRUE" EGameOver ← FALSE
6GameOver ← YES FStores the BOOLEAN value TRUE in GameOver, for example to show the game has ended

Definitions

BOOLEAN

Fill in the Blanks

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

1.
DECLARE GameOver : _______
2.
GameOver ← _____
3.
_______ IsRaining : BOOLEAN
4.
IF Lives = 0 THEN GameOver ← ____ ENDIF
5.
DECLARE LoggedIn : BOOLEAN LoggedIn ← TRUE OUTPUT ________

Spot the Error

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

Question 1
A DECLARE GameOver : BOOLEAN
B GameOver ← "FALSE"
C IF GameOver = TRUE THEN
D OUTPUT "Game over"
E ENDIF
Question 2
A DECLARE Passed : BOOLEAN
B DECLARE Score : INTEGER
C Score ← 72
D Passed ← 1
E OUTPUT Passed
Question 3
A DECLARE IsOpen : BOOLEAN
B IsOpen ← TRUE
C IF IsOpen = "TRUE" THEN
D OUTPUT "Open"
E ENDIF
Question 4
A DECLARE Lives : INTEGER
B DECLARE Alive : BOOLEAN
C Alive ← Lives
D OUTPUT Alive
Question 5
A DECLARE Done : BOOLEAN
B Done = FALSE
C OUTPUT Done

Answer Key

BOOLEAN data type
Section A: Quick Questions
Q1
B — DECLARE GameOver : BOOLEAN
Q2
A — Two: TRUE and FALSE
Q3
A — GameOver ← TRUE
Q4
B — They are keywords, not strings
Q5
A — Whether the player has won (yes or no)
Section B: Match the Pairs
Q1
DECLARE GameOver : BOOLEAN → Creates a variable called GameOver that can only store TRUE or FALSE
Q2
GameOver ← TRUE → Stores the BOOLEAN value TRUE in GameOver, for example to show the game has ended
Q3
A BOOLEAN variable can hold yes/no information, such as whether a player has finished the level → DECLARE LevelComplete : BOOLEAN
Q4
TRUE and FALSE are keywords, so they are written without quotes when assigned → GameOver ← FALSE
Q5
GameOver ← "TRUE" → TRUE is in quotes, so it is a STRING and not a BOOLEAN value. It should be GameOver ← TRUE
Q6
GameOver ← YES → YES is not a BOOLEAN value. A BOOLEAN can only be TRUE or FALSE, so use GameOver ← TRUE
Section C: Definitions
Q1
BOOLEAN — A data type with only two possible values, TRUE or FALSE, written without quotes. Used for yes/no information, e.g. DECLARE GameOver : BOOLEAN
Section D: Fill in the Blanks
Q1
DECLARE GameOver : BOOLEAN
Q2
GameOver ← FALSE
Q3
DECLARE IsRaining : BOOLEAN
Q4
IF Lives = 0 THEN GameOver ← TRUE ENDIF
Q5
DECLARE LoggedIn : BOOLEAN LoggedIn ← TRUE OUTPUT LoggedIn
Section E: Spot the Error
Q1
B — FALSE is a keyword, not a string. With quotes it becomes a STRING, which cannot be stored in a BOOLEAN. It should be GameOver ← FALSE.
Q2
D — A BOOLEAN variable can only hold TRUE or FALSE. The number 1 is an INTEGER, so it must be Passed ← TRUE.
Q3
C — TRUE must be written without quotes. "TRUE" is a string, not a BOOLEAN value. It should be IF IsOpen = TRUE THEN.
Q4
C — Lives is an INTEGER, so it cannot be assigned to a BOOLEAN variable. Use a comparison that gives TRUE or FALSE, such as Alive ← Lives > 0.
Q5
B — Assignment uses the ← operator, not =. A line starting Done = FALSE is a comparison, not an assignment. It should be Done ← FALSE.