Topic 0 · Programming Fundamentals (Python)
Computer Science · Topic Cheatsheet

Topic 0 · Programming Fundamentals (Python)

23 key results accumulated across 4 chapters.

Variable
Ch 1
A named box in memory. `x = 25` stores 25; a later `x = 78` replaces it.
= vs ==
Ch 1
`=` stores a value; `==` tests equality.
// and %
Ch 1
`//` floor-divides; `% 10` gives the last digit, `// 10` drops it.
while loop
Ch 1
Repeat *while* a condition is true: init → test → update, or it never stops.
for / range
Ch 1
`for i in range(a, b):` runs i = a … b−1 → b−a times.
if / elif / else
Ch 1
Runs the FIRST true branch only; put narrow conditions first.
Tracing
Ch 1
Track every variable line-by-line — the #1 exam skill.
IB pseudocode
Ch 1
`loop while … end loop`, `if … then … end if`, `output` — exam answers use this, not Python.
Function
Ch 2
`def avg(a,b,c): return (a+b+c)/3`. Define once, call many.
Parameter vs argument
Ch 2
Parameter = name in the def; argument = value passed in the call.
return
Ch 2
Sends a value back AND ends the function. `return` ≠ `print`.
Scope
Ch 2
A name made inside a function is local — gone when it ends.
Value vs reference
Ch 2
Reassigning an int doesn't affect the caller; *mutating* a list does.
List
Ch 3
`nums = [10,20,30]`; `nums[0]` is 10; `nums[-1]` is the last.
Zero-indexed
Ch 3
First is index 0; last is `len(nums)-1`.
Logical size
Ch 3
Track a counter n for used slots; loop `range(n)`, not full length.
2-D list
Ch 3
`table[r][c]` = row r, column c (both from 0).
Nested loop
Ch 3
Outer rows × inner columns = rows×cols iterations.
Test case
Ch 4
Specific input + expected output. Cover normal, boundary, erroneous.
Boundary
Ch 4
Edges of valid range (0, MAX, empty, full). Off-by-one bugs hide here.
Black-box
Ch 4
Tests behaviour from outside — only inputs/outputs.
White-box
Ch 4
Tests internals — code coverage, every branch.
Debug method
Ch 4
Reproduce → isolate → hypothesise → fix → re-test (don't skip the last).