Assignment ← versus comparison =

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

Assignment ← versus comparison =

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line stores the value 5 in the variable Score?
A Score ← 5
B Score = 5
2. In this line, what does = do? IF Score = 5 THEN
A Tests whether Score is equal to 5
B Stores 5 in Score
3. Which is the correct way to write an assignment in 0478 pseudocode?
A Total = Total + 1
B Total ← Total + 1
4. What result does the condition Score = 5 give when Score holds 7?
A Score becomes 5
B FALSE
5. Which condition correctly tests that Score is NOT equal to 10?
A IF Score <> 10 THEN
B IF Score ← 10 THEN

Match the Pairs

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

Left columnRight column
1Score ← 5 AUses the assignment arrow inside a condition. A condition must test equality with =, so it should be IF Score = 5 THEN.
2IF Score = 5 THEN BStores the value 5 in the variable Score (assignment)
3Use <> to test that two values are not equal CIF Score <> 5 THEN
4Assignment changes the stored value of a variable, so Lives goes down by one DLives ← Lives - 1
5Score = 5 ETests whether Score is equal to 5, giving TRUE or FALSE
6IF Score ← 5 THEN FUses = to store a value. In 0478 pseudocode = is only for comparison, so assignment must be written Score ← 5.

Definitions

Score ← 5

Fill in the Blanks

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

1.
Score _ 5
2.
IF Score _ 5 THEN
3.
IF Lives __ 0 THEN
4.
Count ← 0 Count _ Count + 1
5.
REPEAT INPUT Guess UNTIL Guess _ Secret

Spot the Error

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

Question 1
A Score = 0
B INPUT Guess
C IF Guess = 5
D THEN
E Score ← 10
F ENDIF
Question 2
A DECLARE Age : INTEGER
B INPUT Age
C IF Age ← 18
D THEN
E OUTPUT "Adult"
F ENDIF
Question 3
A Attempts ← 0
B INPUT Code
C WHILE Code <> 1234 DO
D Attempts = Attempts + 1
E INPUT Code
F ENDWHILE
Question 4
A INPUT Pin
B Tries ← 1
C IF Pin != 1234
D THEN
E OUTPUT "Wrong PIN"
F ENDIF
Question 5
A 3 ← Lives
B INPUT Hit
C IF Hit = "Y"
D THEN
E Lives ← Lives - 1
F ENDIF

Answer Key

Assignment ← versus comparison =
Section A: Quick Questions
Q1
A — Score ← 5
Q2
A — Tests whether Score is equal to 5
Q3
B — Total ← Total + 1
Q4
B — FALSE
Q5
A — IF Score <> 10 THEN
Section B: Match the Pairs
Q1
Score ← 5 → Stores the value 5 in the variable Score (assignment)
Q2
IF Score = 5 THEN → Tests whether Score is equal to 5, giving TRUE or FALSE
Q3
Use <> to test that two values are not equal → IF Score <> 5 THEN
Q4
Assignment changes the stored value of a variable, so Lives goes down by one → Lives ← Lives - 1
Q5
Score = 5 → Uses = to store a value. In 0478 pseudocode = is only for comparison, so assignment must be written Score ← 5.
Q6
IF Score ← 5 THEN → Uses the assignment arrow inside a condition. A condition must test equality with =, so it should be IF Score = 5 THEN.
Section C: Definitions
Q1
Score ← 5 — ← stores a value in a variable, so Score ← 5 saves 5 in Score. = only tests if two values are equal, as in IF Score = 5, and gives TRUE or FALSE. <> tests not equal.
Section D: Fill in the Blanks
Q1
Score ← 5
Q2
IF Score = 5 THEN
Q3
IF Lives <> 0 THEN
Q4
Count ← 0 Count ← Count + 1
Q5
REPEAT INPUT Guess UNTIL Guess = Secret
Section E: Spot the Error
Q1
A — Storing a value in a variable needs the assignment arrow, so it should be Score ← 0. A single = only tests whether two values are equal.
Q2
C — An IF condition must test a value, so it needs = to compare. It should be IF Age = 18. The ← arrow would try to store 18 in Age.
Q3
D — This line stores a new value, so it needs the assignment arrow: Attempts ← Attempts + 1. Using = only compares and does not change Attempts.
Q4
C — In 0478 pseudocode, not equal is written <>, not !=. The line should be IF Pin <> 1234.
Q5
A — The variable goes on the left of the arrow and the value on the right. It should be Lives ← 3, which stores 3 in Lives.