Writing a sequence in Cambridge pseudocode

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

Writing a sequence in Cambridge pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which program is a sequence?
A INPUT Num, then IF Num > 5 THEN OUTPUT Num, then ENDIF
B INPUT Num, then Total <- Num * 2, then OUTPUT Total
2. A program takes a number, doubles it and shows the answer. What is the correct order?
A OUTPUT Answer, then Answer <- Num * 2, then INPUT Num
B INPUT Num, then Answer <- Num * 2, then OUTPUT Answer
3. Which line is the PROCESS step in an input-process-output sequence?
A Area <- Length * Width
B INPUT Length
4. What is OUTPUT Total after these lines run? Total <- 5 Total <- Total + 3
A 8
B 5
5. What happens if you swap these two lines? X <- 4 OUTPUT X
A X has no value when it is output, so the output is wrong or an error
B The output is still 4 because the order does not matter

Match the Pairs

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

Left columnRight column
1INPUT Price Total <- Price * 2 OUTPUT Total AAssignment uses = instead of the arrow <-. It should be Score <- 10.
2Total <- Price * 2 INPUT Price OUTPUT Total BOUTPUT comes before the assignment, so Total has no value when it is output. The two statements must be swapped.
3A sequence program starts by declaring its variables, then takes input, then outputs a result CA <- 5 B <- A + 3 OUTPUT B
4A program with no selection or iteration is a pure sequence: every statement runs exactly once, in order DA sequence of input, then process, then output: the statements run once each, in order, from top to bottom
5OUTPUT Total Total <- 4 + 6 EThe order is wrong: Price is used in the calculation before it has been given a value from INPUT
6DECLARE Score : INTEGER Score = 10 OUTPUT Score FDECLARE Age : INTEGER INPUT Age OUTPUT Age + 1

Definitions

sequence

Fill in the Blanks

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

1.
DECLARE Price : INTEGER _____ Price OUTPUT Price
2.
INPUT Price Total ← Price _ 3 OUTPUT Total
3.
Count _ 0 Count ← Count + 1 OUTPUT Count
4.
_______ Name : STRING INPUT Name OUTPUT Name
5.
INPUT Mins Secs ← Mins * 60 ______ Secs

Spot the Error

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

Question 1
A DECLARE Price : REAL
B DECLARE Qty : INTEGER
C INPUT Price
D Qty INPUT
E OUTPUT Price * Qty
Question 2
A DECLARE Age = INTEGER
B INPUT Age
C Age <- Age + 1
D OUTPUT Age
Question 3
A DECLARE Cost : REAL
B INPUT Cost
C OUTPUT "Cost: " Cost
Question 4
A DECLARE Total : INTEGER
B Total = 10 + 5
C Total <- Total * 2
D OUTPUT Total
Question 5
A DECLARE Num : INTEGER
B INPUT Num
C Num := Num * 2
D OUTPUT Num

Answer Key

Writing a sequence in Cambridge pseudocode
Section A: Quick Questions
Q1
B — INPUT Num, then Total <- Num * 2, then OUTPUT Total
Q2
B — INPUT Num, then Answer <- Num * 2, then OUTPUT Answer
Q3
A — Area <- Length * Width
Q4
A — 8
Q5
A — X has no value when it is output, so the output is wrong or an error
Section B: Match the Pairs
Q1
INPUT Price Total <- Price * 2 OUTPUT Total → A sequence of input, then process, then output: the statements run once each, in order, from top to bottom
Q2
Total <- Price * 2 INPUT Price OUTPUT Total → The order is wrong: Price is used in the calculation before it has been given a value from INPUT
Q3
A sequence program starts by declaring its variables, then takes input, then outputs a result → DECLARE Age : INTEGER INPUT Age OUTPUT Age + 1
Q4
A program with no selection or iteration is a pure sequence: every statement runs exactly once, in order → A <- 5 B <- A + 3 OUTPUT B
Q5
OUTPUT Total Total <- 4 + 6 → OUTPUT comes before the assignment, so Total has no value when it is output. The two statements must be swapped.
Q6
DECLARE Score : INTEGER Score = 10 OUTPUT Score → Assignment uses = instead of the arrow <-. It should be Score <- 10.
Section C: Definitions
Q1
sequence — A program made of statements like DECLARE, <-, INPUT and OUTPUT that run one after another from top to bottom, with no selection or iteration. Changing the order changes the result.
Section D: Fill in the Blanks
Q1
DECLARE Price : INTEGER INPUT Price OUTPUT Price
Q2
INPUT Price Total ← Price * 3 OUTPUT Total
Q3
Count ← 0 Count ← Count + 1 OUTPUT Count
Q4
DECLARE Name : STRING INPUT Name OUTPUT Name
Q5
INPUT Mins Secs ← Mins * 60 OUTPUT Secs
Section E: Spot the Error
Q1
D — The keyword INPUT must come first, followed by the variable name. The line should be INPUT Qty.
Q2
A — A DECLARE statement uses a colon between the identifier and the data type. It should be DECLARE Age : INTEGER.
Q3
C — Items in an OUTPUT statement must be separated by commas. It should be OUTPUT "Cost: ", Cost.
Q4
B — Assignment uses the arrow <-. The = sign is a comparison operator in Cambridge pseudocode. It should be Total <- 10 + 5.
Q5
C — Cambridge pseudocode assigns with <-, not :=. The line should be Num <- Num * 2.