Program and source code

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

Program and source code

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is source code?
A The 1s and 0s that the CPU runs directly
B The instructions a programmer writes in a programming language
2. A program is a list of instructions. Which statement is correct?
A The computer follows the instructions in order, one after another
B The computer picks the instructions in a random order
3. Who normally writes source code?
A A programmer
B The CPU
4. Can the CPU run source code written in Python directly?
A No, it must be translated into machine code first
B Yes, the CPU understands Python directly
5. Which one is source code?
A 10110001 00000101
B total = price * quantity

Match the Pairs

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

Left columnRight column
1print("Hello") AMachine code that the CPU can run directly; it is what source code becomes after translation
210110000 01100001 BA line of source code written by a programmer in a high-level language (Python); it is one instruction in a program
3A program is a list of instructions that the computer follows in order, one after another CThe command is spelled wrongly, which breaks the language's rules. It should be print("Hello"), or the translator will report an error.
4A programming language has rules (syntax) that programmers must follow when they write source code DThe CPU only runs machine code. Source code must first be translated by a compiler, an interpreter or an assembler.
5The CPU can run source code directly without any translation Eif score >= 50: print("Pass")
6prnit("Hello") Fname = input("Name? ") print("Hi " + name)

Definitions

source code

Fill in the Blanks

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

1.
# This is human-written ______ code print("Hi")
2.
name = "Sam" _____(name)
3.
x = 5 y = x + 2 print(_)
4.
# The CPU needs a __________ to run this print("Hi")
5.
# Python's rules are its ______ print("Hi")

Spot the Error

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

Question 1
A name = input("Name: ")
B age = 15
C total = age + 1
D print(name, total
Question 2
A x = 5
B y = 10
C prnt(x + y)
Question 3
A total = 0
B total = totl + 5
C print(total)
Question 4
A score = 10
B bonus = 5
C score = score + bonus
D print score
Question 5
A name = "Sam"
B age = 15
C Print(name, age)

Answer Key

Program and source code
Section A: Quick Questions
Q1
B — The instructions a programmer writes in a programming language
Q2
A — The computer follows the instructions in order, one after another
Q3
A — A programmer
Q4
A — No, it must be translated into machine code first
Q5
B — total = price * quantity
Section B: Match the Pairs
Q1
print("Hello") → A line of source code written by a programmer in a high-level language (Python); it is one instruction in a program
Q2
10110000 01100001 → Machine code that the CPU can run directly; it is what source code becomes after translation
Q3
A program is a list of instructions that the computer follows in order, one after another → name = input("Name? ") print("Hi " + name)
Q4
A programming language has rules (syntax) that programmers must follow when they write source code → if score >= 50: print("Pass")
Q5
The CPU can run source code directly without any translation → The CPU only runs machine code. Source code must first be translated by a compiler, an interpreter or an assembler.
Q6
prnit("Hello") → The command is spelled wrongly, which breaks the language's rules. It should be print("Hello"), or the translator will report an error.
Section C: Definitions
Q1
source code — The instructions a programmer writes in a programming language. The CPU cannot run it until a translator turns it into machine code.
Section D: Fill in the Blanks
Q1
# This is human-written source code print("Hi")
Q2
name = "Sam" print(name)
Q3
x = 5 y = x + 2 print(y)
Q4
# The CPU needs a translator to run this print("Hi")
Q5
# Python's rules are its syntax print("Hi")
Section E: Spot the Error
Q1
D — Every programming language has rules for how source code is written. This line is missing the closing bracket. It should be print(name, total).
Q2
C — The language only knows the instruction print. A misspelt keyword breaks the rules of the language, so the translator cannot understand the line. It should be print(x + y).
Q3
B — The variable name is misspelt, so the instruction refers to something that does not exist. It should be total = total + 5.
Q4
D — In Python, print is a function, so its input must be in brackets. Source code must follow the language's rules. It should be print(score).
Q5
C — Python is case-sensitive, so Print is not the same instruction as print. The translator does not recognise it. It should be print(name, age).