Python Foundations

Introduction

What Cambridge 9618 Paper 4 is, how it is marked, the question types that always appear, what examiners reward, and how Cambridge pseudocode maps to Python. Start here before any other chapter.

1.1 What Is Paper 4?

Paper 4 is the practical programming paper in Cambridge International A Level Computer Science (9618). Unlike Papers 1, 2 and 3 — which are written exams — Paper 4 requires you to write and run actual programs on a computer.

  • It tests your ability to write working programs, not just talk about them.
  • Every syllabus topic — OOP, ADTs, file handling, algorithms — is tested through code you write, run and screenshot.
  • OOP and ADTs are core skills, not optional extras.
2h 30
Time Allowed
75
Total Marks
3
Compulsory Questions
Python
Approved Language
Evidence Document:
  • The Evidence Document is where you paste all your code and screenshots.
  • Cambridge examiners mark from this document — they do not run your programs themselves.
  • If your code is not in the Evidence Document, it cannot be marked.
  • If screenshots are missing, you lose marks even if the code is correct.

1.2 Paper 3 vs Paper 4

Paper 4 differs from Paper 3 in one important way: Paper 3 tests whether you understand concepts; Paper 4 tests whether you can actually implement them.

AspectPaper 3Paper 4
FormatWritten examPractical on a computer
Answer typePseudocode, written answersWorking program code
EvidenceExam bookletEvidence Document (code + screenshots)
Marks awarded forCorrect explanation, correct pseudocodeCorrect output, structure and logic
OOP tested asDescribe / trace / write pseudocodeWrite full working class definitions in Python
Exam tip:
  • Paper 4 rewards working code that produces correct output.
  • A perfectly explained theory answer (Paper 3 style) scores nothing in Paper 4 if the program does not run.

1.3 Guaranteed Question Types

Exam tip:
  • Paper 4 follows a very consistent structure year after year.
  • Knowing what always appears lets you prepare with focus — not waste time on topics that rarely show up.

From many years of past papers, you should always expect these three question types:

Question 1 — OOP

  • Define one or more classes
  • Attributes, methods, constructor
  • Create and use objects
  • Often inheritance or containment

Question 2 — ADT

  • Stack (LIFO), Queue (FIFO)
  • Linked list, Binary tree
  • Manual implementation only
  • Handle full and empty conditions

Question 3 — Mixed

  • Algorithms: searching or sorting
  • File handling (read/write/append)
  • Recursion, structured data
  • Most open-ended question
OOP is not optional:
  • OOP appears in every single Paper 4.
  • It is always the first or a major question and typically carries the most marks.
  • If you are not comfortable writing classes in Python, this is where to start.

1.4 What Examiners Want

Cambridge Paper 4 examiners are not looking for the cleverest solution. They are looking for code that is readable, correct, and traceable. A simple 20-line solution that works scores more than a clever 5-line solution that is hard to follow.

✓ Examiners reward

Simple, readable programs
Step-by-step logic
Correct use of variables and data structures
Programs that produce correct output
Code that follows the given pseudocode
Clear, meaningful variable names
Correct class structure for OOP
Handling edge cases (full, empty, invalid)

✗ Examiners do NOT reward

Clever one-liners or shortcuts
Advanced features not in the syllabus
List comprehensions, lambda, map/filter
Overly compact or minified code
Solutions that skip algorithm steps
Code that is difficult to trace by hand
Missing screenshots in the Evidence Document
Correct-looking code with wrong output
Common mistakes that lose marks:
  • Starting to code before reading the question fully — missing a sub-part loses all its marks.
  • Not including screenshots — code without a running screenshot loses method marks.
  • Using unsuitable features (e.g. sorted() instead of writing the sort).
  • Not following the given pseudocode — your Python should mirror its logic and names.
  • Building GUI or web applications — Paper 4 is console-only.

1.5 Python for Paper 4

Python is one of the approved languages for Cambridge 9618 Paper 4 (alongside Java and Visual Basic .NET). Python is used throughout this site because it is clear, readable, and its structure maps closely to Cambridge pseudocode.

Console means:
  • All user interaction is through input() and print().
  • All storage is through variables, lists or text files.
  • If a solution needs anything beyond this, it is not suitable for Paper 4.

Safe features vs features to avoid

FeatureUse in P4?Reason
if / elif / else✓ SafeCore construct, maps to pseudocode
for and while loops✓ SafeCore construct
Lists (used as arrays)✓ SafeRequired for ADTs
Functions and procedures✓ SafeRequired for structured programming
Classes and objects (OOP)✓ SafeRequired — OOP always tested
Basic file handling✓ SafeCore P4 skill
try / except✓ SafeUsed for exception handling
List comprehensions✗ AvoidHides logic; hard to trace
lambda, map, filter✗ AvoidAdvanced; not rewarded
sorted() / .sort()✗ AvoidSorting needs a manual algorithm
GUI libraries (tkinter)✗ AvoidConsole only — not accepted
Unnecessary imports✗ AvoidOnly import what is needed (e.g. random)

1.6 Pseudocode → Python Mapping

Cambridge Paper 4 questions often provide pseudocode describing the algorithm. Your Python must follow the same logic order, use similar variable names, and implement each step clearly. Do not restructure the algorithm unless asked.

Cambridge Pseudocode

DECLARE total : INTEGER
total <- 0
FOR i <- 1 TO 5
  OUTPUT "Enter score: "
  INPUT score
  total <- total + score
NEXT i
OUTPUT "Total: ", total

Python (Paper 4 style)

total = 0
for i in range(1, 6):
    score = int(input("Enter score: "))
    total = total + score
print("Total:", total)

Cambridge Pseudocode — OOP

CLASS Animal
  PRIVATE name : STRING
  PRIVATE sound : STRING

  PUBLIC PROCEDURE NEW(n, s)
    name <- n
    sound <- s
  ENDPROCEDURE

  PUBLIC FUNCTION makeSound() RETURNS STRING
    RETURN name & " says " & sound
  ENDFUNCTION
ENDCLASS

Python (Paper 4 style)

class Animal:
    def __init__(self, n, s):
        self.__name = n
        self.__sound = s

    def makeSound(self):
        return self.__name + " says " + self.__sound

a = Animal("Cat", "meow")
print(a.makeSound())

Quick pseudocode → Python reference

Pseudocode constructPython equivalent
FOR i ← 1 TO nfor i in range(1, n+1):
WHILE cond DO ... ENDWHILEwhile cond:
REPEAT ... UNTIL condwhile True: ... if cond: break
IF ... THEN ... ELSE ... ENDIFif ... : else:
INPUT xx = input("...") (+ cast)
OUTPUT xprint(x)
x DIV yx // y
x MOD yx % y
DECLARE x : INTEGERx = 0 (initial value)
CLASS ... ENDCLASSclass ...:
PRIVATE attributeself.__attribute
PUBLIC PROCEDURE NEW(...)def __init__(self, ...):

Key Points Summary

Paper 4 is a practical exam — you write and run real programs on a computer.
3 compulsory questions, 75 marks, 2 hours 30 minutes (about 25 marks per question).
OOP is always tested (usually Q1) — start here if you are not confident with classes.
ADTs (stack, queue, linked list, binary tree) are always tested — manual implementation only.
All Python must run in console mode — no GUI, no web, no external libraries.
Write clear, readable, step-by-step code — cleverness is not rewarded.
Follow the given pseudocode logic and use similar variable names.
Paste BOTH code AND screenshots into the Evidence Document for every part.
Avoid list comprehensions, lambda, map/filter and built-in sorted() in sorting tasks.
Use input() and print() for all interaction; only import what is needed (e.g. random).

1.7 Practice Tasks

Fifteen exam-style tasks. Click Hint for bullet-point guidance, then Help to reveal a worked Python solution.

1Practice Task — Print output [2 marks]
Write a Python statement that prints the exact line: Hello, Paper 4!
2Practice Task — Variables and data types [3 marks]
Declare four variables: age = 17 (int), height = 1.75 (float), name = "Sam" (str), and is_ready = True (bool). Print each on its own line.
3Practice Task — Reading input [2 marks]
Ask the user "Enter your name: " using input(), store it in a variable, then print a greeting that uses the name.
4Practice Task — Comments [2 marks]
Write a line of code that assigns total = 100 and add a comment explaining what it stores.
5Practice Task — Variable naming rules [3 marks]
State three rules for naming a variable in Python. Give one example of an INVALID name.
6Practice Task — Type conversion [4 marks]
Read a number from the user as a string, convert it to an int, then print the number plus 10.
7Practice Task — Arithmetic operators [4 marks]
With a = 17 and b = 5, print the result of: a + b, a - b, a * b, a / b, a // b, a % b, a ** b.
8Practice Task — Operator precedence [4 marks]
Predict the output of: print(2 + 3 * 4) and print((2 + 3) * 4). Explain the difference.
9Practice Task — String concatenation [3 marks]
Join first = "Ada" and last = "Lovelace" with a space into full_name, then print it.
10Practice Task — f-strings [4 marks]
Given name = "Sam" and score = 87, use an f-string to print: Sam scored 87 marks.
11Practice Task — Swapping variables [3 marks]
Swap the values of a = 5 and b = 9 WITHOUT using a third variable. Print before and after.
12Practice Task — Multiple assignment [4 marks]
Use a single Python statement to assign x = 1, y = 2, z = 3. Then print their sum using an f-string.
13Practice Task — Type errors [6 marks]
The code below crashes. Explain why and fix it so it prints the doubled number. num = input("Enter: ") print(num * 2)
14Practice Task — f-string formatting [6 marks]
Given price = 9.5 and qty = 3, use ONE f-string to print: Total: $28.50 (3 items @ $9.50). Show 2 decimal places for every money value.
15Practice Task — Exam-style: output and variables [8 marks]
Write a complete program that: (a) asks the user for their name [1]; (b) asks for their age and converts it to int [2]; (c) calculates age in months (age * 12) [2]; (d) prints, using an f-string with 1 decimal place: "Hi NAME, you are about X.0 months old." [2]; (e) adds a comment on the month line explaining the calc [1].

Question Bank

Answer all questions, then press Submit Quiz to see your score.

0/12 answered

Question 1Multiple Choice

Paper 4 of Cambridge 9618 is best described as:

Question 2True / False

Paper 4 has 75 marks and lasts 2 hours 30 minutes.

Question 3Multiple Choice

What is the purpose of the Evidence Document in Paper 4?

Question 4Multiple Choice

Which question type is guaranteed to appear in every Paper 4?

Question 5True / False

Using sorted() to sort a list is rewarded in Paper 4 sorting tasks.

Question 6Multiple Choice

Which of these should you AVOID in Paper 4 Python?

Question 7Multiple Choice

The pseudocode `FOR i ← 1 TO 5` translates to which Python line?

Question 8True / False

Python input() returns a string, so numeric input must be cast with int() or float().

Question 9Multiple Choice

Which Python expression gives the remainder (pseudocode MOD)?

Question 10Multiple Choice

How is a pseudocode PRIVATE attribute represented in Python OOP?

Question 11True / False

If a question provides pseudocode, you should restructure the algorithm to be more "Pythonic".

Question 12Multiple Choice

Which is a common reason students lose marks in Paper 4?

Answer all 12 questions to enable submission.