Sequence: instructions run in order

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

Sequence: instructions run in order

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In a program using sequence, which statement runs first?
A The statement with the shortest code runs first
B The top statement runs first, then the next one down
2. What does this code print? x = 5 x = x + 2 print(x)
A 7
B 5
3. What does this code print? x = 4 print(x) x = 9
A 4
B 9
4. Two lines are swapped: A: total = 10, then print(total) B: print(total), then total = 10 Which version runs without a NameError?
A A: total = 10, then print(total)
B B: print(total), then total = 10
5. True or false: swapping two statements in a sequence can change the result of a program.
A False
B True

Match the Pairs

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

Left columnRight column
1x = 5 x = x + 2 print(x) ACauses an error because total is used before it is given a value
2print(total) total = 10 BThe output statement is placed before the calculation, so area has no value when it is printed. Move the calculation above print.
3Swapping two statements can change the output, because each line runs in order CRuns top to bottom and prints 7, because x is changed before it is printed
4A simple input-process-output program follows sequence: input first, then process, then output Da = 3 a = a * 2 print(a) # prints 6
5print(area) area = width * height EThe update comes after print, so the output shows 10 instead of 15. Put the update before print.
6score = 10 print(score) score = score + 5 Fn = int(input()) double = n * 2 print(double)

Definitions

sequence

Fill in the Blanks

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

1.
name = input("Name: ") print("Hi " + ____)
2.
total = 10 total = total + 5 print(_____)
3.
age = ___(input("Age: ")) print(age + 1)
4.
count = 1 count = count _ 1 print(count)
5.
print("Start") _____("Middle") print("End")

Spot the Error

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

Question 1
A score = 10
B score = score + 5
C print(total)
Question 2
A width = 4
B height = area / width
C area = width * height
D print(area)
Question 3
A x = x + 2
B x = x * 3
C print(x)
Question 4
A n = 3
B n = n + 2
C n = n * 2
D print n
Question 5
A age = input('Age: ')
B nxt = age + 1
C print(nxt)

Answer Key

Sequence: instructions run in order
Section A: Quick Questions
Q1
B — The top statement runs first, then the next one down
Q2
A — 7
Q3
A — 4
Q4
A — A: total = 10, then print(total)
Q5
B — True
Section B: Match the Pairs
Q1
x = 5 x = x + 2 print(x) → Runs top to bottom and prints 7, because x is changed before it is printed
Q2
print(total) total = 10 → Causes an error because total is used before it is given a value
Q3
Swapping two statements can change the output, because each line runs in order → a = 3 a = a * 2 print(a) # prints 6
Q4
A simple input-process-output program follows sequence: input first, then process, then output → n = int(input()) double = n * 2 print(double)
Q5
print(area) area = width * height → The output statement is placed before the calculation, so area has no value when it is printed. Move the calculation above print.
Q6
score = 10 print(score) score = score + 5 → The update comes after print, so the output shows 10 instead of 15. Put the update before print.
Section C: Definitions
Q1
sequence — A control structure where statements run one after another, top to bottom, so changing their order can change the result.
Section D: Fill in the Blanks
Q1
name = input("Name: ") print("Hi " + name)
Q2
total = 10 total = total + 5 print(total)
Q3
age = int(input("Age: ")) print(age + 1)
Q4
count = 1 count = count + 1 print(count)
Q5
print("Start") print("Middle") print("End")
Section E: Spot the Error
Q1
C — The variable total was never created. The statements run in order and the value is stored in score, so the last line should be print(score).
Q2
B — This line uses area before it exists. area is only created on line 3, and Python runs the lines top to bottom. It should be height = 3.
Q3
A — This is the first statement, so x has no value yet and Python raises a NameError. The program must start by giving x a value, x = 2.
Q4
D — In Python 3, print is a function and needs brackets. The last statement should be print(n), which outputs 10 after the three lines run in order.
Q5
B — input() gives a string, so adding 1 to it causes a TypeError. The process step must convert it first: nxt = int(age) + 1.