Assignment with ← (7a)

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

Assignment with ← (7a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly stores the value 0 in the variable Counter?
A 0 ← Counter
B Counter ← 0
2. In the statement Total ← 25, which part receives the value?
A Total, on the left of the arrow
B 25, on the right of the arrow
3. What does Counter ← Counter + 1 do?
A It increases Counter by 1
B It checks whether Counter equals Counter + 1
4. Counter currently holds 4. What does it hold after Counter ← Counter + 1 runs?
A 4
B 5
5. Score is declared as INTEGER. Which assignment is valid?
A Score ← 10
B Score ← "ten"

Match the Pairs

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

Left columnRight column
1Counter ← 0 AWorks out Counter + 1 using the old value, then stores the result back in Counter, adding 1 to it
2Counter ← Counter + 1 BStores the value 0 in the variable Counter, so it starts counting from zero
3The variable being assigned to is written on the left of the arrow and the value on the right CThe variable and value are the wrong way round. The variable must be on the left of the arrow, so this should be Counter ← 0.
4The value assigned must match the data type of the variable, such as a STRING variable receiving text in quotes DAge is an INTEGER variable, but it is given a STRING value. The value must match the data type, so it should be Age ← 12.
50 ← Counter EName ← "Sam"
6Age ← "twelve" FTotal ← 25

Definitions

Counter ← 0

Fill in the Blanks

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

1.
DECLARE Counter : INTEGER Counter _ 0
2.
DECLARE Counter : INTEGER _______ ← 0
3.
DECLARE Counter : INTEGER Counter ← 0 Counter ← _______ + 1
4.
DECLARE Name : ______ Name ← "Sam"
5.
DECLARE Counter : INTEGER Counter ← 0 Counter ← Counter _ 1

Spot the Error

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

Question 1
A DECLARE Counter : INTEGER
B Counter ← 0
C Counter + 1 ← Counter
D OUTPUT Counter
Question 2
A 0 ← Counter
B Counter ← Counter + 1
C OUTPUT Counter
Question 3
A DECLARE Name : STRING
B Name ← 5
C OUTPUT Name
Question 4
A DECLARE Total : INTEGER
B Total ← 0
C Total ← Total + 2
D Total = Total + 5
E OUTPUT Total
Question 5
A Score := 10
B Score ← Score + 5
C OUTPUT Score

Answer Key

Assignment with ← (7a)
Section A: Quick Questions
Q1
B — Counter ← 0
Q2
A — Total, on the left of the arrow
Q3
A — It increases Counter by 1
Q4
B — 5
Q5
A — Score ← 10
Section B: Match the Pairs
Q1
Counter ← 0 → Stores the value 0 in the variable Counter, so it starts counting from zero
Q2
Counter ← Counter + 1 → Works out Counter + 1 using the old value, then stores the result back in Counter, adding 1 to it
Q3
The variable being assigned to is written on the left of the arrow and the value on the right → Total ← 25
Q4
The value assigned must match the data type of the variable, such as a STRING variable receiving text in quotes → Name ← "Sam"
Q5
0 ← Counter → The variable and value are the wrong way round. The variable must be on the left of the arrow, so this should be Counter ← 0.
Q6
Age ← "twelve" → Age is an INTEGER variable, but it is given a STRING value. The value must match the data type, so it should be Age ← 12.
Section C: Definitions
Q1
Counter ← 0 — The ← assignment operator stores the value on its right in the variable on its left. Here 0 is stored in Counter. The value must match the variable's data type.
Section D: Fill in the Blanks
Q1
DECLARE Counter : INTEGER Counter ← 0
Q2
DECLARE Counter : INTEGER Counter ← 0
Q3
DECLARE Counter : INTEGER Counter ← 0 Counter ← Counter + 1
Q4
DECLARE Name : STRING Name ← "Sam"
Q5
DECLARE Counter : INTEGER Counter ← 0 Counter ← Counter + 1
Section E: Spot the Error
Q1
C — The variable being assigned must be on the left of the ← and the value on the right. It should be Counter ← Counter + 1.
Q2
A — The assignment is the wrong way round. The variable goes on the left and the value on the right, so it should be Counter ← 0.
Q3
B — Name is a STRING, so the value stored must be a string such as "Sam". A number does not match the variable's data type.
Q4
D — In Cambridge pseudocode = is used for comparing values, not for assigning. The line should use the assignment operator: Total ← Total + 5.
Q5
A — The := symbol is not Cambridge pseudocode. Assignment is written with ←, so it should be Score ← 10.