Software programming
Software programming in NCEA Level 1 Digital Technologies assesses whether you can turn a problem into a working, tested program and explain the decisions you made. Expect questions on algorithms, control structures, data types, functions, and debugging.
Core rules and concepts
- Every program combines sequence, selection (
if/elif/else) and iteration (for/while). Useforwhen the number of repeats is known; usewhilewhen it depends on a condition. - Declare variables with meaningful names. Know integer, float, string and Boolean.
=assigns;==compares. - A function should do one job, take parameters, and return a value. Variables created inside a function are local.
- Test with normal, boundary and invalid data. Record expected versus actual output.
- Debug by reproducing the fault, isolating the line, and changing one thing at a time.
Worked example
A function must return the average of a list of marks, or None if the list is empty.
def average(marks):
if len(marks) == 0:
return None
total = 0
for mark in marks:
total += mark
return total / len(marks)
Reasoning: the empty-list check prevents division by zero; the loop accumulates; division after the loop gives a float. Test [], [5], [2, 4] and a list containing 0.
Traps
- Off-by-one errors in
range()and list indexes. - Using integer division when a decimal average is required.
- Printing inside a function instead of returning.
- Changing a list while iterating over it.
- Claiming code is correct without evidence from tests.