How unit 1 is examined
This unit is a practical lab: Python exercises such as sorting and searching, and Pygame simulations. No question from the supplied papers was tagged to it.
Python Programming Exercises and Pygame Simulations
Not asked since 2022
Definition. The lab unit applies core Python (variables, loops, functions, lists) to exercises such as sorting and searching, and uses the Pygame library to draw and animate simulations.
Key points.
- Exercises use basic Python constructs: input and output, conditions, loops, functions and lists.
- Sorting and searching are typical exercises; bubble sort repeatedly swaps adjacent out-of-order items, and binary search halves a sorted list each step.
- Pygame simulations run a loop that handles events, updates object positions and redraws the screen every frame.
a = [5, 2, 9, 1]
for i in range(len(a)):
for j in range(len(a) - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
print(a) # [1, 2, 5, 9]
Last-minute revision
- The unit is a lab: Python exercises plus Pygame simulations.
- Bubble sort swaps adjacent out-of-order items; sorted output of [5, 2, 9, 1] is [1, 2, 5, 9].
- Binary search needs a sorted list and halves the range each step; 9 is at index 3.
- A Pygame program loops: handle events, update state, redraw.
- Python lists are mutable; swap with
a[j], a[j+1] = a[j+1], a[j]. - No past questions were tagged to this unit.
- Sorting and searching are the likeliest exercises to appear.
- Binary search takes about log2(n) comparisons; bubble sort takes about n squared.
Memory hooks
- Bubble sort: big values bubble up to the end.
- Binary search: split the sorted list in half, like opening a dictionary in the middle.
- Pygame loop: Events, Update, Draw.
Coverage checklist
- Python Programming Exercises and Pygame Simulations: no past questions in the supplied papers; definition and key points covered.