Assignment with <-

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

Assignment with <-

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line stores the value 0 in the variable Count?
A Count <- 0
B 0 <- Count
2. After the line Score <- 10 + 5, what is stored in Score?
A 10 + 5
B 15
3. Which statement ADDS Number to the running total?
A Total = Total + Number
B Total <- Total + Number
4. Count is 3. After Count <- 7 runs, what does Count hold?
A 7
B 10
5. What does the <- operator do in Count <- 0?
A It stores 0 in Count
B It tests whether Count equals 0

Match the Pairs

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

Left columnRight column
1Count ← 0 AThe value and the variable are the wrong way round. The variable must be on the left of ← and the value on the right.
2Total ← Total + Number BArea ← Length * Width
3Assigning the result of a calculation: the right side is worked out, then stored in the variable on the left CStores the constant 0 in the variable Count, so Count starts at 0
4Reassigning a variable: a new value replaces the old value that was stored before DAdds Number to the current Total and stores the new result back in Total
510 ← Count E= is used instead of ←. In Cambridge pseudocode = tests whether two values are equal, it does not store a value.
6Count = 0 FScore ← 10 Score ← 15

Definitions

Count <- 0

Fill in the Blanks

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

1.
Count __ 0
2.
Total <- Total _ Number
3.
Area <- Length _ Width
4.
Score <- 10 _____ <- Score + 5
5.
Lives <- 3 Lives <- Lives _ 1

Spot the Error

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

Question 1
A DECLARE Total : INTEGER
B Total <- 0
C INPUT Number
D Total = Total + Number
E OUTPUT Total
Question 2
A 0 <- Count
B Count <- Count + 1
C OUTPUT Count
Question 3
A DECLARE Price : REAL
B Price <- 4.50
C Price * 3 <- Cost
D OUTPUT Cost
Question 4
A DECLARE Score : INTEGER
B Score <= 10
C Score <- Score + 5
D OUTPUT Score
Question 5
A Lives -> 3
B Lives <- Lives - 1
C OUTPUT Lives

Answer Key

Assignment with <-
Section A: Quick Questions
Q1
A — Count <- 0
Q2
B — 15
Q3
B — Total <- Total + Number
Q4
A — 7
Q5
A — It stores 0 in Count
Section B: Match the Pairs
Q1
Count ← 0 → Stores the constant 0 in the variable Count, so Count starts at 0
Q2
Total ← Total + Number → Adds Number to the current Total and stores the new result back in Total
Q3
Assigning the result of a calculation: the right side is worked out, then stored in the variable on the left → Area ← Length * Width
Q4
Reassigning a variable: a new value replaces the old value that was stored before → Score ← 10 Score ← 15
Q5
10 ← Count → The value and the variable are the wrong way round. The variable must be on the left of ← and the value on the right.
Q6
Count = 0 → = is used instead of ←. In Cambridge pseudocode = tests whether two values are equal, it does not store a value.
Section C: Definitions
Q1
Count <- 0 — The <- operator stores the value on its right in the variable on its left. Count <- 0 puts 0 into Count. It is assignment, not a test for equality.
Section D: Fill in the Blanks
Q1
Count <- 0
Q2
Total <- Total + Number
Q3
Area <- Length * Width
Q4
Score <- 10 Score <- Score + 5
Q5
Lives <- 3 Lives <- Lives - 1
Section E: Spot the Error
Q1
D — Assignment uses the <- operator, not =. In Cambridge pseudocode = is a comparison, so the line should be Total <- Total + Number.
Q2
A — The value goes on the right of <- and the variable on the left. The line should be Count <- 0.
Q3
C — The variable being assigned must be on the left of <-. The calculation goes on the right: Cost <- Price * 3.
Q4
B — <= means less than or equal to. It is a comparison and does not store anything. Assignment needs the arrow: Score <- 10.
Q5
A — The assignment arrow points left, towards the variable receiving the value. The line should be Lives <- 3.