Python sum as language-dependent code optimisation

2025-hsc-se-q04 · Multiple Choice · 1 mark

Source: NESA 2025 HSC Software Engineering HSC Q4

Question

Fragment 1 and Fragment 2 are Python code that achieve the same purpose.

Fragment 1

numbers = [1, 2, 3, 4, 5]
total = 0

for num in numbers:
    total += num

print(total)

Fragment 2

numbers = [1, 2, 3, 4, 5]
print(sum(numbers))

Fragment 2 is an example of

Options

Select one answer
Reveal answer

C. language-dependent code optimisation.

Marking rubric

MarksDescription
1Identifies the correct answer.

Explanation

The second fragment uses Python's built-in sum function to express the same operation more directly using a language-specific feature.

Metadata

Submitter
Seed data
Created
2026-05-02
Status
published
Syllabus
y12-project-language-dependent-optimisation
Tags
Python code optimisation built-in functions language-dependent optimisation