BSEH SS Computer Science study materials
BSEH SS Computer Science study resources

BSEH SS Computer Science: Python Programming

BSEH SS Computer Science · Work through your exam, one topic at a time.

All guide sections

Python Programming

What this domain tests

Python Programming tests syntax, indentation, data types, operators, selection, loops, functions, strings, lists, dictionaries, exceptions and basic file handling. Questions often require predicting output or finding an error.

Core rules

  • Indentation defines blocks; a colon ends the header line. Use 4 spaces consistently.
  • input() returns a string; convert with int(), float() or eval() only when appropriate.
  • / gives float division; // floor division; % remainder; ** exponent.
  • range(start, stop, step) excludes stop. Lists are mutable and 0-indexed; strings are immutable.
  • Functions use def; parameters are local unless declared global. return sends a value back; printing is not returning.
  • Exceptions use try/except; files should be closed, preferably with with open(...) as f:.

Worked example

total = 0
for i in range(2, 10, 3):
    total += i
print(total)

range(2,10,3) produces 2, 5, 8. total becomes 2, then 7, then 15. Output: 15. Reasoning: start at 2, add 3 each time, stop before 10.

Traps

print('2' + '3') gives 23, not 5. range(5) gives 0–4. A function without return returns None. Changing a list while iterating over it skips elements. = assigns; == compares. Indentation errors are syntax errors, not runtime warnings.