Skip to main content

Programming constructs and code for QCE Digital Solutions Unit 3

Syllabus dot point

“Code programming constructs including variables, data types, operators, control structures, functions and arrays to implement an algorithm as a working, testable digital solution”

QCEDigital SolutionsUnit 3: Digital innovation6 min read

Quick answer

Programming constructs are the building blocks that implement an algorithm in code: variables hold typed data, operators combine values, control structures (IF, WHILE, FOR) direct flow, functions package reusable logic with parameters and a return value, and arrays or lists store collections you process with a loop.

Jump to a section
  1. What this dot point is asking
  2. Variables, data types and operators
  3. Control structures in code
  4. Functions and parameters
  5. Arrays and lists
  6. Writing testable code
  7. How this appears in IA2
  8. Exam-style questions

What this dot point is asking

QCAA wants you to translate an algorithm into working code using the core constructs every imperative language shares: variables and data types, operators, control structures, functions and collections such as arrays. In IA2 you build a digital solution, so your code must run, be readable and be testable. The examples below use Python, the most common Queensland school language, but the constructs map directly to JavaScript or any procedural language.

Variables, data types and operators

A variable is a named store for a value. Each value has a data type that fixes what operations are valid: integer, float, string, Boolean. Choosing the right type matters for both correctness and storage efficiency.

age = 17              # int
gpa = 6.25            # float
name = "Priya"        # string
is_enrolled = True    # bool

Operators fall into groups: arithmetic (+ - * / // % **), relational (== != < > <= >=) and logical (and or not). The // operator is integer division and % is modulo, both useful for digit manipulation and even/odd tests.

Control structures in code

Selection and iteration look almost identical to pseudocode, which is why a clean algorithm translates quickly.

def classify(mark):
    if mark >= 85:
        return "A"
    elif mark >= 70:
        return "B"
    elif mark >= 50:
        return "C"
    else:
        return "Fail"
total = 0
for n in range(1, 11):     # 1..10 inclusive
    if n % 2 == 0:
        total += n
print(total)               # 30

range(1, 11) stops before 11, a deliberate convention that prevents off-by-one errors once you internalise it.

Functions and parameters

A function packages logic behind a name so it can be reused and tested in isolation. It takes parameters (inputs) and usually returns a value (output). Functions are the main tool for managing complexity: decompose a large problem into small, independently testable units.

A validated input function
def get_valid_mark():
    """Return a mark between 0 and 100, re-prompting on bad input."""
    while True:
        raw = input("Enter mark (0-100): ")
        if raw.isdigit():
            mark = int(raw)
            if 0 <= mark <= 100:
                return mark
        print("Invalid - enter a whole number 0 to 100.")

This single function combines a type check (isdigit), a range check and a re-prompt loop. It returns only valid data, so the calling code never has to defend against bad input again. QCAA rewards exactly this kind of reusable, defensive design in IA2.

Arrays and lists

A collection stores many values under one name, indexed from 0. You process collections with a loop, which is the foundation of data-driven solutions.

marks = [55, 88, 72, 49, 91]
total = 0
for m in marks:
    total += m
average = total / len(marks)
print(round(average, 1))     # 71.0

Indexing (marks[0] is 55), slicing and built-in functions (sum, max, min, len) make collection handling concise, but you should still be able to write the manual loop, because QCAA may ask you to demonstrate the underlying logic.

Writing testable code

A digital solution must be verifiable. Good practice:

  • keep functions short and single-purpose;
  • use clear identifiers and comments that explain why, not what;
  • separate input, processing and output;
  • write test cases that include normal, boundary and erroneous data.

Testing with a table of inputs and expected outputs is direct evidence for the IA2 evaluation criterion.

Common traps
  • Type mismatches. input() returns a string; adding it to an integer raises an error. Convert with int() or float() first.
  • Mutating while iterating. Removing items from a list inside a for loop over the same list skips elements. Build a new list instead.
  • Forgetting the return. A function that computes a value but never returns it leaves the caller with None.
  • Magic numbers. Hard-coding 85 in three places makes the code fragile; store thresholds in named constants.
  • No validation. Trusting raw user input is the top cause of crashes in student solutions; validate at the boundary.

How this appears in IA2

IA2 is a digital solution: working, documented code that meets the prescribed requirements. Markers look for correct use of constructs, decomposition into functions, validation of inputs and a clear test plan showing the solution behaves correctly across normal and edge cases. Submit code that runs, annotate the non-obvious parts, and pair it with evidence (screenshots or a test table) that each requirement is met.

Exam-style questions

Questions in the style of QCAA exam questions on this dot point, each with a worked answer. They are written by ExamExplained unless tagged "Past paper"; the year shows the paper a question is modelled on.

Practice8 marks
Use pseudocode to symbolise a function that accepts an array of integer test scores, returns the average, and is called from a main routine that then outputs whether the average is a pass (50 or more). Explain how parameters and the return value make the function reusable.
Show worked answer →

An 8 mark symbolise-and-explain answer rewards a correct function plus the call and an account of parameters.

FUNCTION average(scores)
    SET total TO 0
    FOR i = 0 TO scores.length - 1
        SET total TO total + scores[i]
    END FOR
    RETURN total / scores.length
END FUNCTION

SET avg TO average(testScores)
IF avg >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail"

Explain: the parameter scores lets the function work on any array passed in, and the return value hands the result back to the caller, so the same function can be reused with different data without rewriting the logic. Markers reward the accumulator loop, the RETURN, the call assigning the result, and the parameter or reuse explanation.

Practice4 marks
Explain the difference between a selection construct and an iteration construct, and give a coded example of each.
Show worked answer →

A 4 mark explain answer needs the purpose of each construct with examples.

Selection chooses between paths once, based on a condition, for example IF score >= 50 THEN OUTPUT "Pass". Iteration repeats a block while a condition holds or for a known count, for example FOR i = 1 TO 5 DO OUTPUT i.

Selection decides whether to run code; iteration decides how many times. Markers reward the choose-versus-repeat distinction and one valid example of each.

Practise this

Sources & how we know this

ExamExplained