Computational Thinking and Python Programming Fundamentals
Domain 3 - Computational Thinking and Python Programming Fundamentals. This domain tests decomposition and abstraction as much as syntax: can you read a short program, trace its state line by line, and predict the exact output?
Core rules and concepts
- Four pillars: decomposition, pattern recognition, abstraction, algorithm design. A valid algorithm must be unambiguous, finite and produce output for valid input.
- Types: int, float, str, bool, list, tuple, dict, set. Use
type()to confirm;int('7'),float('2.5'),str(7)convert.input()always returns a string. - Operators:
/is true division (float),//is floor division,%is remainder,**is power. Precedence runs**, unary minus,* / // %,+ -, comparisons,not,and,or. - Control flow:
if / elif / else,forover iterables,whilewith a condition that changes. Blocks are delimited by indentation, not braces.range(a, b)stops beforeb. - Functions:
def name(params):withreturn; a function with noreturnyieldsNone. Parameters are local names, but mutating a list argument changes the caller's list.
Worked example
total = 0
for n in range(1, 6):
if n % 2 == 0:
total += n
Trace with state: range(1, 6) yields 1, 2, 3, 4, 5. n=1 is odd, skipped. n=2 even, total=2. n=3 skipped. n=4 even, total=6. n=5 skipped. The loop ends and the program prints 6. Notice that 6 (the stop bound) is never processed.
Traps that cost marks
- Forgetting that
rangeexcludes its stop value. - Confusing
=(assignment) with==(comparison). - Writing
7/2when the answer needs7//2; in Python-7 // 2is-4, not-3. - Expecting
0.1 + 0.2 == 0.3to be True; floating point gives 0.30000000000000004. - Adding a string to an integer (
'3' + 2) raises a TypeError; convert first.