A-Level Computer Science revision: Programming Fundamentals. Learning objectives, key points, worked examples and practice questions across AQA, Edexcel, OCR, WJEC and CCEA.
๐ Key Points
Key Fact: Data types: int, float, bool, char, string; type casting; constants vs variables
Question: Write a function that reads a file of integers and returns the median
Model Answer:
def median_from_file(filename):
with open(filename) as f:
nums = sorted(int(line.strip()) for line in f if line.strip())
n = len(nums)
if n == 0: return None
mid = n // 2
return nums[mid] if n % 2 else (nums[mid-1] + nums[mid]) / 2
โ Practice Questions
Model answers are being added progressively - questions marked ✗ don't have one yet. Cross-check with your teacher or the official mark scheme.
Questions:
Write a program that validates email format using regex✗ answer coming soon
Implement a recursive factorial function✗ answer coming soon
Create a menu-driven calculator with functions✗ answer coming soon
Write a function to count word frequencies in a text file✗ answer coming soon
Handle division by zero with try/except✗ answer coming soon
Worked example (10 min): Model the example question: Write a function that reads a file of integers and returns the median. Solution: def median_from_file(filename):
with open(filename) as f:
nums = sorted(int(line.strip()) for line in f if line.strip())
n = len(nums)
if n == 0: return None
mid = n // 2
return nums[mid] if n % 2 else (nums[mid-1] + nums[mid]) / 2
Practice (10 min): Students attempt the practice questions independently; circulate and support.
Plenary (5 min): Review answers and address misconceptions.
๐ Homework
Write a program that validates email format using regex
Implement a recursive factorial function
Create a menu-driven calculator with functions
Write a function to count word frequencies in a text file
Handle division by zero with try/except
๐งพ Assessment
Check practice answers against the model answer; use the built-in practice questions as formative assessment.