The five basic features of programming

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

The five basic features of programming

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which list correctly names the five basic features of programming?
A Variables, flowcharts, pixels, syntax, hardware
B Variables, control structures, data structures, syntax, libraries and classes
2. Which line of Python uses a VARIABLE?
A import random
B score = 10
3. Which code is a CONTROL STRUCTURE?
A for i in range(5):
B names = ['Ava', 'Liam']
4. Which code is a DATA STRUCTURE?
A marks = [88, 74, 95]
B if marks > 50:
5. Which statement describes SYNTAX in programming?
A The rules for how code must be written so the computer can read it
B A named place that stores a value

Match the Pairs

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

Left columnRight column
1score = 0 AA library: ready-made code that is brought into the program so you can reuse it
2import random BThe variable total is used before it has been given a value, so Python cannot find it.
3A control structure decides which code runs or how many times it repeats CA variable: a named place that stores a value the program can use and change
4A data structure stores a collection of related values under one name Dfor i in range(5): print(i)
5if score > 50 print("Pass") ESyntax error: the if line is missing its colon at the end. Syntax is the set of rules the code must follow.
6print(total) total = 10 Fscores = [88, 74, 91]

Definitions

five features of programming

Fill in the Blanks

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

1.
score = 10 print(_____)
2.
lives = 3 _____ lives > 0: lives = lives - 1
3.
names = ["Ava", "Liam", "Mia"] print(names[_])
4.
age = 16 if age __ 16: print("Year 11")
5.
import ______ print(random.randint(1, 6))

Spot the Error

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

Question 1
A score = 0
B score = scor + 10
C print(score)
Question 2
A age = 16
B if age >= 16
C print('Can drive')
Question 3
A colours = ['red', 'blue']
B colours.append('green')
C print(colours[3])
Question 4
A import random
B n = randint(1, 6)
C print(n)
Question 5
A class Dog:
B def __init__(self, name):
C name = name
D pet = Dog('Rex')

Answer Key

The five basic features of programming
Section A: Quick Questions
Q1
B — Variables, control structures, data structures, syntax, libraries and classes
Q2
B — score = 10
Q3
A — for i in range(5):
Q4
A — marks = [88, 74, 95]
Q5
A — The rules for how code must be written so the computer can read it
Section B: Match the Pairs
Q1
score = 0 → A variable: a named place that stores a value the program can use and change
Q2
import random → A library: ready-made code that is brought into the program so you can reuse it
Q3
A control structure decides which code runs or how many times it repeats → for i in range(5): print(i)
Q4
A data structure stores a collection of related values under one name → scores = [88, 74, 91]
Q5
if score > 50 print("Pass") → Syntax error: the if line is missing its colon at the end. Syntax is the set of rules the code must follow.
Q6
print(total) total = 10 → The variable total is used before it has been given a value, so Python cannot find it.
Section C: Definitions
Q1
five features of programming — Every program is built from five features: variables, control structures, data structures, syntax, and libraries and classes.
Section D: Fill in the Blanks
Q1
score = 10 print(score)
Q2
lives = 3 while lives > 0: lives = lives - 1
Q3
names = ["Ava", "Liam", "Mia"] print(names[0])
Q4
age = 16 if age == 16: print("Year 11")
Q5
import random print(random.randint(1, 6))
Section E: Spot the Error
Q1
B — The variable is misspelled as scor, which was never created, so Python raises a NameError. It should be score = score + 10.
Q2
B — A control structure like if needs a colon at the end of its line (syntax). It should be if age >= 16:
Q3
C — The list has 3 items, so the valid indexes are 0, 1 and 2. Index 3 causes an IndexError. It should be colours[2].
Q4
B — With import random, the function must be called through the library name. It should be random.randint(1, 6).
Q5
C — This only changes a local variable, so the object never stores the name. It should be self.name = name.