Sequence

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

Sequence

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement describes sequence?
A The computer runs all the statements at the same time
B Statements run one after another in the order they are written
2. In which order should this algorithm be written to add two numbers and show the answer?
A INPUT A, INPUT B, Total ← A + B, OUTPUT Total
B OUTPUT Total, Total ← A + B, INPUT A, INPUT B
3. Total ← Price * 2 is written BEFORE INPUT Price. What happens?
A The computer looks ahead and uses the value input on the next line
B The calculation uses a value that has not been input yet, so the result is wrong
4. Two statements are swapped: OUTPUT Total now comes before Total ← A + B. What is output?
A The old value of Total, not the new sum
B The new sum, because the calculation is done anyway
5. Which way do you read an algorithm to follow its sequence?
A From the top line to the bottom line
B From the bottom line to the top line

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 AThe calculation comes before the INPUT statements, so Length and Width have no values when Area is worked out. Move the calculation after both INPUTs.
2OUTPUT Total Total ← Price * 2 INPUT Price BA sequence in the wrong order: Total is output before it has been calculated or Price has been input
3Swapping two statements changes the result: here A is set to 5, then B copies A, so B is 5 CA ← 5 B ← A OUTPUT B
4Reading an algorithm from top to bottom: the second assignment replaces the first value, so the output is 9 DX ← 4 X ← 9 OUTPUT X
5Area ← Length * Width INPUT Length INPUT Width OUTPUT Area EA sequence: the value is input first, then calculated, then output, in that order from top to bottom
6INPUT Mark OUTPUT Percent Percent ← Mark / 50 * 100 FOUTPUT is placed before the calculation, so Percent is displayed before it has been worked out. Swap the last two lines.

Definitions

sequence

Fill in the Blanks

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

1.
_____ Price Total ← Price * 2 OUTPUT Total
2.
INPUT Length Area ← Length * Length OUTPUT ____
3.
Temp ← A A ← B B ← ____
4.
INPUT Price Tax _ Price * 0.2 OUTPUT Tax
5.
Total ← 10 Total ← Total _ 2 OUTPUT Total

Spot the Error

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

Question 1
A INPUT Length
B INPUT Width
C Area ← Length * Width
D OUTPUT Cost
E OUTPUT Cost
Question 2
A Double ← Num * 2
B Double ← Num * 2
C OUTPUT Double
Question 3
A INPUT Price
B Tax ← Total * 0.2
C Total ← Price + Tax
D OUTPUT Total
Question 4
A Total ← 0
B INPUT A
C Total ← Total + A
D Total ← Total + B
E Total ← Total + B
F OUTPUT Total
Question 5
A OUTPUT "Enter Celsius"
B OUTPUT Fahr
C Fahr ← Celsius * 9 / 5 + 32
D OUTPUT Fahr

Answer Key

Sequence
Section A: Quick Questions
Q1
B — Statements run one after another in the order they are written
Q2
A — INPUT A, INPUT B, Total ← A + B, OUTPUT Total
Q3
B — The calculation uses a value that has not been input yet, so the result is wrong
Q4
A — The old value of Total, not the new sum
Q5
A — From the top line to the bottom line
Section B: Match the Pairs
Q1
INPUT Price Total ← Price * 2 OUTPUT Total → A sequence: the value is input first, then calculated, then output, in that order from top to bottom
Q2
OUTPUT Total Total ← Price * 2 INPUT Price → A sequence in the wrong order: Total is output before it has been calculated or Price has been input
Q3
Swapping two statements changes the result: here A is set to 5, then B copies A, so B is 5 → A ← 5 B ← A OUTPUT B
Q4
Reading an algorithm from top to bottom: the second assignment replaces the first value, so the output is 9 → X ← 4 X ← 9 OUTPUT X
Q5
Area ← Length * Width INPUT Length INPUT Width OUTPUT Area → The calculation comes before the INPUT statements, so Length and Width have no values when Area is worked out. Move the calculation after both INPUTs.
Q6
INPUT Mark OUTPUT Percent Percent ← Mark / 50 * 100 → OUTPUT is placed before the calculation, so Percent is displayed before it has been worked out. Swap the last two lines.
Section C: Definitions
Q1
sequence — Statements are carried out one after another in the order they are written, from top to bottom, so changing the order can change the result.
Section D: Fill in the Blanks
Q1
INPUT Price Total ← Price * 2 OUTPUT Total
Q2
INPUT Length Area ← Length * Length OUTPUT Area
Q3
Temp ← A A ← B B ← Temp
Q4
INPUT Price Tax ← Price * 0.2 OUTPUT Tax
Q5
Total ← 10 Total ← Total * 2 OUTPUT Total
Section E: Spot the Error
Q1
D — Line 4 outputs Cost before it has been calculated. Statements run top to bottom, so the calculation Cost ← Area * 3 must come before OUTPUT Cost.
Q2
A — Line 1 uses Num before it has been input. The INPUT Num statement must come first so that Num has a value when the calculation runs.
Q3
B — Line 2 uses Total before it has been worked out on line 3. Tax should be calculated from Price, which was input on line 1.
Q4
D — Line 4 adds B to Total before B has been input. The INPUT B statement must come first, then the addition.
Q5
B — Line 2 outputs Fahr before the value has been input and calculated. The INPUT must come first, then the calculation, then OUTPUT.