Python for IGCSE Computer Science
Complete Enhanced Workbook for Grades 9–10
This enhanced edition contains clear explanations, fully formatted code blocks, mini-projects, practice exercises,
and teaching tips for Cambridge IGCSE Computer Science programming with Python.
Section 1 – Introduction to Python & the Exam
Why Python for IGCSE: Easy to learn, matches Cambridge pseudocode structure, widely used.
Exam Role: Appears in Paper 2 (Problem-solving & Programming). Tasks include translating pseudocode, writing
Python code, debugging.
Setup: Install Python (3.x), use IDE like Thonny or Repl.it.
Mini-Project: First Program
print("Hello, IGCSE!")
Section 2 – Programming Fundamentals
Variables store values. Types: int, float, str, bool. Type casting converts between types: int(), float(), str().
Operators: + - * / // % **, == != > < >= <=, and or not.
Mini-Project: Simple Interest Calculator
principal = float(input("Enter principal: "))
rate = float(input("Enter rate: "))
time = float(input("Enter time: "))
si = (principal * rate * time) / 100
print(f"Simple Interest = {si}")
Section 3 – String Handling
Strings are indexed from 0. Methods: upper(), lower(), find(), replace(), split(), strip().
Mini-Project: Username Generator
first = input("First: ").strip()
last = input("Last: ").strip()
username = first[0].lower() + last.lower()
print("Username:", username)
Section 4 – Control Structures
Use if, elif, else for decision making. Combine conditions with and/or/not. Nested if handles deeper checks.
Mini-Project: ATM Withdrawal
balance = 5000
amt = int(input("Amount: "))
if amt <= balance and amt % 100 == 0:
balance -= amt
print("Collect cash")
else:
print("Invalid or insufficient funds")
Section 5 – Iteration (Loops)
for loops repeat fixed times; while loops repeat until condition false. Use break to exit loop early, continue to skip
iteration.
Mini-Project: Guess the Number
import random
secret = random.randint(1, 10)
guess = 0
while guess != secret:
guess = int(input("Guess: "))
if guess < secret: print("Too low!")
elif guess > secret: print("Too high!")
print("Correct!")
Section 6 – Lists (1D Arrays)
Lists hold multiple values. Append adds, remove deletes. Loop through lists to process all items.
Mini-Project: Student Marks Database
marks = []
for i in range(5):
marks.append(int(input("Mark: ")))
avg = sum(marks) / len(marks)
print("Average:", avg)
Section 7 – Functions & Procedures
Functions return values; procedures perform tasks without returning values. Use def to define.
Mini-Project: Average Marks
def average(m):
return sum(m) / len(m)
marks = [85,90,78,92,88]
print("Average:", average(marks))
Section 8 – File Handling
Open files with open() or with. Modes: r=read, w=write, a=append.
Mini-Project: Contact Book
def add_contact(name, phone):
with open("contacts.txt", "a") as f:
f.write(f"{name},{phone}\n")
Section 9 – Data Validation
Check that inputs meet requirements before using them. Range checks, loops, and try/except prevent errors.
Mini-Project: Secure Login
for attempt in range(3):
user = input("User: "); pwd = input("Pass: ")
if user=="admin" and pwd=="1234":
print("Login OK"); break
Section 10 – Debugging & Testing
Errors: Syntax (break rules), Logic (wrong result), Runtime (fail during execution). Use print() to trace values.
Create test tables with inputs/expected outputs.
Mini-Project: Bug Fix Example
num = int(input("Enter: "))
if num % 2 == 0: print("Even")
else: print("Odd")
Section 11 – Exam Practice
Practice translating pseudocode to Python and solving multi-step problems.
Mini-Project: Shop Program
products = {"Pen": 10, "Book": 50, "Bag": 300}
while True:
print("\nAvailable products:")
for item, price in products.items():
print(f"{item}: ■{price}")
choice = input("Enter product name: ")
if choice in products:
qty = int(input("Enter quantity: "))
total = products[choice] * qty
print(f"Total cost: ■{total}")
else:
print("Product not found.")
again = input("Buy again? (yes/no): ").lower()
if again != "yes":
break