Assignment with ← (7d)

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

Assignment with ← (7d)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line sets Total to 0 in Cambridge pseudocode?
A 0 ← Total
B Total ← 0
2. Total ← 5 is followed by Total ← 8. What is Total afterwards?
A 8
B 13
3. Which line adds Number to the running total?
A Total ← Total + Number
B Total + Number ← Total
4. Total is 10 and Number is 4. After Total ← Total + Number, what is Total?
A 4
B 14
5. In pseudocode, what does the ← arrow do?
A It stores a value in a variable
B It checks if two values are equal

Match the Pairs

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

Left columnRight column
1Total ← 0 AScore ← 5 Score ← 8
2Total ← Total + Number BStores the value 0 in the variable Total, so the total starts at zero
3Assigning a new value to a variable replaces the value it held before CThe variable and the value are the wrong way round. The variable must be on the left of the arrow and the value on the right, so it should be Total ← 0.
4The arrow stores the value on its right in the variable on its left DIn Cambridge pseudocode = is used to compare values, not to store them. To set Total to 0 you must write Total ← 0.
50 ← Total EAdds Number to the current value of Total and stores the answer back in Total
6Total = 0 FCount ← 10

Definitions

Total ← 0

Fill in the Blanks

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

1.
Total _ 0
2.
Total ← Total _ Number
3.
Total ← 10 Total ← Total + 5 OUTPUT _____
4.
IF Total _ 0 THEN OUTPUT "Empty" ENDIF
5.
DECLARE Total : INTEGER _____ ← 0

Spot the Error

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

Question 1
A Total ← 0
B 5 ← Number
C Total ← Total + Number
D OUTPUT Total
Question 2
A Total ← 0
B Num1 ← 4
C Num2 ← 6
D Num1 + Num2 ← Total
E OUTPUT Total
Question 3
A Total ← 0
B Number ← 7
C Total ← Number
D OUTPUT Total
Question 4
A Lives ← 3
B Lives ← Live - 1
C OUTPUT Lives
Question 5
A DECLARE Age : INTEGER
B Age ← 15
C Age + 1
D OUTPUT Age

Answer Key

Assignment with ← (7d)
Section A: Quick Questions
Q1
B — Total ← 0
Q2
A — 8
Q3
A — Total ← Total + Number
Q4
B — 14
Q5
A — It stores a value in a variable
Section B: Match the Pairs
Q1
Total ← 0 → Stores the value 0 in the variable Total, so the total starts at zero
Q2
Total ← Total + Number → Adds Number to the current value of Total and stores the answer back in Total
Q3
Assigning a new value to a variable replaces the value it held before → Score ← 5 Score ← 8
Q4
The arrow stores the value on its right in the variable on its left → Count ← 10
Q5
0 ← Total → The variable and the value are the wrong way round. The variable must be on the left of the arrow and the value on the right, so it should be Total ← 0.
Q6
Total = 0 → In Cambridge pseudocode = is used to compare values, not to store them. To set Total to 0 you must write Total ← 0.
Section C: Definitions
Q1
Total ← 0 — The ← arrow stores the value on its right in the variable on its left. Total ← 0 sets Total to 0. A new assignment replaces the old value. It is not the same as = used to compare.
Section D: Fill in the Blanks
Q1
Total ← 0
Q2
Total ← Total + Number
Q3
Total ← 10 Total ← Total + 5 OUTPUT Total
Q4
IF Total = 0 THEN OUTPUT "Empty" ENDIF
Q5
DECLARE Total : INTEGER Total ← 0
Section E: Spot the Error
Q1
B — The arrow stores the value on its right in the variable on its left. A variable must be on the left, so this should be Number ← 5.
Q2
D — The left side of ← must be a single variable that receives the value. The calculation goes on the right: Total ← Num1 + Num2.
Q3
C — A new assignment replaces the old value. This overwrites Total instead of adding to it. It should be Total ← Total + Number.
Q4
B — The variable name is misspelt. Live is a different variable from Lives, so the line should be Lives ← Lives - 1.
Q5
C — This calculates a value but never stores it, so Age does not change. It needs the assignment arrow: Age ← Age + 1.