NCEA Level 2 Digital Technologies study materials
NCEA Level 2 Digital Technologies study resources

NCEA Level 2 Digital Technologies practice questions

One question at a time. Build your NCEA Level 2 Digital Technologies understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Software programming

In a Python program, a variable named total is assigned the integer 5 and later reassigned the string "five". What best describes what happens when the program runs?

  1. Python raises a TypeError at the first assignment because total must keep one type.
  2. Python allows the reassignment because variable types are checked at runtime, not fixed at declaration. Correct answer.
  3. Python converts the integer 5 into the string "5" automatically to keep types consistent.
  4. Python raises a SyntaxError before any code runs because two types appear for one name.

Explanation

Python is dynamically typed: a name is just a reference that can be rebound to an object of any type while the program runs. The interpreter does not lock a variable to an initial type, so assigning an integer then a string is legal. Type errors only arise when an operation is invalid for the current object.

Question 2Software programming

A programmer writes the boolean expression below. Which value does it evaluate to? not (3 > 5) and (4 == 4)

  1. None
  2. It raises a TypeError
  3. False
  4. True Correct answer.

Explanation

The comparison 3 > 5 is False, so not (False) becomes True. The comparison 4 == 4 is True, and True and True evaluates to True. Boolean operators are applied after the comparisons inside the parentheses.

Question 3Software programming

Which statement correctly describes the role of a function's return value in a program?

  1. It permanently stores the result in a global variable for later functions to read.
  2. It restarts the function so the body runs again with the same arguments.
  3. It prints the result to the screen automatically whenever the function finishes.
  4. It passes a result back to the code that called the function so it can be used or stored. Correct answer.

Explanation

A return statement ends the function and hands a value back to the caller, which may assign it, pass it on, or ignore it. Printing is a separate action done with output statements, not an automatic effect of returning. The returned value has no inherent global scope.

Question 4Software programming

A list called scores contains the values [10, 20, 30, 40]. What is the value of scores[2] in Python?

  1. 30 Correct answer.
  2. 10
  3. 40
  4. 20

Explanation

Python list indexing starts at 0, so index 0 holds 10, index 1 holds 20, and index 2 holds 30. The value at position 2 is therefore 30. Accessing index 4 would be out of range for this four-element list.

Question 5Software programming

Which loop is most appropriate when the number of repetitions is not known in advance and the loop should continue until a condition becomes false?

  1. A while loop Correct answer.
  2. A for loop over a range
  3. A single if statement
  4. A for loop over a list

Explanation

A while loop checks its condition before each iteration and keeps running while that condition stays true, which suits repetition with an unknown count. A for loop is normally used when iterating over a known sequence or range. An if statement makes a one-off decision and does not repeat.

Question 6Software programming

What is the main purpose of using indentation in Python source code?

  1. It declares the data type of each variable on that line.
  2. It makes the code run faster by grouping similar lines together.
  3. It marks lines as comments so the interpreter ignores them.
  4. It defines which statements belong to a block such as a loop or function body. Correct answer.

Explanation

Python uses indentation as syntax to show block structure, so lines indented under a loop, if, or def form that block's body. Changing indentation changes meaning rather than only appearance. Comments use the hash symbol, and types are not declared by indentation.

Question 7Software programming

A program stores a student's age as the string "16" and needs to add 1 to it. Which operation produces the integer 17?

  1. int(age) + 1 Correct answer.
  2. str(age) + 1
  3. age + 1
  4. float(age + 1)

Explanation

The value is currently text, so it must be converted to a number before arithmetic. int(age) turns "16" into the integer 16, and adding 1 gives 17. Attempting arithmetic directly on the string would raise an error.

Question 8Software programming

Which of the following best describes a syntax error in a program?

  1. Code that breaks the language's grammar rules and is rejected before the program runs. Correct answer.
  2. Code that is grammatically valid but runs too slowly to finish.
  3. Code that crashes only when a particular input value is entered at runtime.
  4. Code that runs but produces an unexpected result because of faulty logic.

Explanation

A syntax error violates the grammar of the language, such as a missing bracket or colon, and the interpreter detects it before execution begins. Logic errors and runtime errors occur while the program is running. Performance problems are not syntax errors.

Question 9Software programming

Consider this loop: total = 0 for n in range(1, 5): total = total + n What is the value of total after the loop finishes?

  1. 10 Correct answer.
  2. 15
  3. 5
  4. 4

Explanation

range(1, 5) produces 1, 2, 3, 4, stopping before 5. Adding these gives 1 + 2 + 3 + 4 = 10. The upper bound in range is exclusive, which is why 5 is not included.

Question 10Software programming

A function is written as: def area(width, height): return width * height Which call correctly uses this function?

  1. area(3)
  2. area(3, 4) Correct answer.
  3. area()
  4. area = 3 * 4

Explanation

The function declares two parameters, width and height, so a valid call must supply two arguments. area(3, 4) passes both and returns 12. Calls with the wrong number of arguments raise a TypeError.

Question 11Software programming

A programmer wants to check whether a number stored in x is between 1 and 10 inclusive. Which condition is correct?

  1. x >= 1 and x <= 10 Correct answer.
  2. x >= 1 and x >= 10
  3. x >= 1 or x <= 10
  4. x > 1 and x < 10

Explanation

Inclusive bounds require >= 1 for the lower limit and <= 10 for the upper limit, joined by and so both must hold. Using or would accept almost any number because one side is usually true. Strict inequalities would wrongly exclude 1 and 10.

Question 12Software programming

A list named names holds several strings. Which code correctly adds the string "Ana" to the end of the list?

  1. names[0] = "Ana"
  2. names.append("Ana") Correct answer.
  3. names + "Ana"
  4. names.add("Ana")

Explanation

The append method adds a single element to the end of a list and modifies it in place. String concatenation cannot be used to add an element to a list. Assigning to an index replaces an existing element rather than extending the list.

Question 13Software programming

A program reads scores into a list and needs to find the largest value. Which approach correctly finds the maximum for a non-empty list?

  1. Set a variable to the first element, then compare each remaining element and update it when a larger one is found. Correct answer.
  2. Set a variable to 0, then compare each element to it and keep the first value checked.
  3. Sort the list and return the first element.
  4. Add all elements together and divide by the number of elements.

Explanation

Starting from the first element guarantees a real value even if all scores are negative, then each later element is compared and the variable updated when larger. Sorting ascending and taking the first element would give the minimum, not the maximum. Averaging returns a mean, not a maximum.

Question 14Software programming

What is the result of the expression 17 // 5 in Python?

  1. 3.4
  2. 4
  3. 2
  4. 3 Correct answer.

Explanation

The // operator performs floor division, dividing and rounding down to the nearest whole number. 17 divided by 5 is 3.4, and flooring gives 3. The single slash / would give the float 3.4 instead.

Question 15Software programming

A programmer writes a loop intended to print the numbers 0 to 4 but uses range(1, 4). What is the actual output?

  1. 1, 2, 3, 4
  2. 0, 1, 2, 3, 4
  3. 1, 2, 3 Correct answer.
  4. 0, 1, 2, 3

Explanation

range(1, 4) starts at 1 and stops before 4, producing 1, 2, 3. The start value is inclusive while the stop value is exclusive. To include 0 the start would need to be 0, and to include 4 the stop would need to be 5.

Question 16Software programming

A function is meant to double a number but is written as: def double(n): n * 2 What is the problem when the call double(5) is made?

  1. The function returns 10 because Python returns the last expression automatically.
  2. The function returns None because the expression result is not returned. Correct answer.
  3. The function returns 5 because the multiplication is ignored but n is returned.
  4. The function raises a TypeError because n cannot be multiplied.

Explanation

Without a return statement, a Python function returns None by default, even if it computes a value internally. The expression n * 2 is evaluated and discarded. Adding return n * 2 would make the function return 10.

Question 17Software programming

Which comparison correctly tests whether two strings a and b hold exactly the same characters in the same order?

  1. a = b
  2. a is b
  3. a == b Correct answer.
  4. a != b

Explanation

The == operator compares values, so it checks whether the two strings contain the same characters in the same order. A single = is assignment and cannot be used inside a condition. The is operator checks object identity, not value equality.

Question 18Software programming

A program must repeatedly ask for a password until the correct one is entered. Which structure best fits this requirement?

  1. A while loop whose condition checks whether the entered password differs from the correct one. Correct answer.
  2. A single if statement that checks the password once.
  3. A function that returns the password without any loop.
  4. A for loop over range(3) that stops after three attempts regardless of input.

Explanation

Because the number of attempts is unknown, a while loop that keeps running while the input is wrong matches the requirement. A for loop with a fixed range would stop after a set number of tries. A single if statement checks only once and cannot repeat.

Question 19Software programming

A list called data contains numbers. A programmer wants a new list of only the even numbers. Which approach correctly builds this list?

  1. Sort data and return the first half of the list.
  2. Loop over data and append every value, then divide each by 2.
  3. Create an empty list, loop over data, and append each value where value % 2 == 0. Correct answer.
  4. Create an empty list and append data[0] only.

Explanation

Testing value % 2 == 0 identifies even numbers because even values have no remainder when divided by 2. Appending only those values to a new list produces the filtered result. Dividing all values or slicing after sorting does not select evens.

Question 20Software programming

A programmer writes a function that is supposed to return the average of a list but divides by len(numbers) - 1. For a list of four values, what effect does this have on the computed average?

  1. It divides the sum by 5, producing a smaller value than the true average.
  2. It raises a ZeroDivisionError for any non-empty list.
  3. It divides the sum by 3 instead of 4, producing a larger value than the true average. Correct answer.
  4. It has no effect because len ignores the subtraction.

Explanation

The true average divides the sum by the number of values, which is 4 here. Using len(numbers) - 1 divides by 3, so the same sum is spread over fewer values and the result is larger. This is a logic error that produces a plausible but incorrect answer.

Question 21Software programming

A 2D list grid represents a table where grid[row][col] holds each cell. What does grid[1][2] refer to?

  1. The value in the second row and third column. Correct answer.
  2. The value in the third row and second column.
  3. The value in the second row and second column.
  4. The value in the first row and second column.

Explanation

Both indexes start at 0, so the first index 1 selects the second row and the second index 2 selects the third column. Reading nested indexes left to right follows row then column. Confusing 0-based with 1-based counting is a common source of off-by-one errors.

Question 22Software programming

A list of numbers is searched using linear search versus binary search. Which statement is accurate about binary search?

  1. It can only be used on lists of strings, not numbers.
  2. It works on unsorted data because it checks every element in turn.
  3. It always examines every element before returning a result.
  4. It requires the data to be sorted and repeatedly halves the search range. Correct answer.

Explanation

Binary search relies on sorted order so it can compare against the middle element and discard half the remaining data each step. This makes it much faster than linear search on large sorted lists. Linear search is the method that checks elements one by one on unsorted data.

Question 23Software programming

Consider this code: count = 0 for i in range(3): for j in range(3): count = count + 1 What is the final value of count?

  1. 3
  2. 6
  3. 9 Correct answer.
  4. 0

Explanation

The outer loop runs three times, and for each outer iteration the inner loop runs three times. The total number of increments is 3 times 3, which is 9. Nested loops multiply their iteration counts rather than adding them.

Question 24Software programming

A function is written to find a value in a list and return its index, but it returns -1 when the value is absent. A caller uses the result directly as an index without checking. What is the risk?

  1. Python raises a SyntaxError because -1 is not a valid integer.
  2. The function returns None, which cannot be used as an index.
  3. The list is automatically extended so that index -1 becomes valid.
  4. Using -1 as an index silently accesses the last element instead of signalling a missing value. Correct answer.

Explanation

In Python a negative index counts from the end, so -1 refers to the last element rather than an error. A caller that does not check for the sentinel value may therefore process the wrong item. This is a design flaw in using -1 as a sentinel when indexes can be negative.

Question 25Software programming

A programmer wants to swap the values of two variables a and b in Python. Which sequence correctly swaps them?

  1. temp = a; a = b; b = temp Correct answer.
  2. a = b; temp = a; b = temp
  3. a = b; b = a
  4. temp = a; a = b; b = a

Explanation

A temporary variable preserves the original value of a before a is overwritten. Assigning a = b then b = temp places the old a into b, completing the swap. Without the temporary, the original value is lost.

Question 26Software programming

In Python, what does the expression 7 % 3 evaluate to?

  1. 0
  2. 2
  3. 1 Correct answer.
  4. 2.33

Explanation

The modulo operator % returns the remainder after integer division. Seven divided by three is two with a remainder of one, so 7 % 3 is 1.

Question 27Software programming

A program needs to store whether a user is logged in, a value that is either true or false. Which Python data type is most appropriate?

  1. float
  2. bool Correct answer.
  3. int
  4. str

Explanation

A boolean (bool) type holds exactly one of two values, True or False, which matches a yes/no state such as logged in. Storing this in a numeric or text type would allow meaningless values.

Question 28Software programming

What is the output of print("Hi" + "there") in Python?

  1. Hithere Correct answer.
  2. Hi there
  3. An error is raised
  4. Hi+there

Explanation

The + operator on two strings performs concatenation, joining them exactly with no added characters. Because no space is inside either string, the result is Hithere.

Question 29Software programming

A program uses the variable name total_score. Which statement about this identifier is correct in Python?

  1. It is only valid inside a function definition.
  2. It is invalid because identifiers cannot contain underscores.
  3. It is invalid because identifiers must start with an uppercase letter.
  4. It is valid and conventionally used for multi-word variable names. Correct answer.

Explanation

Python identifiers may contain letters, digits, and underscores, provided they do not start with a digit. Underscores are the conventional way to separate words in variable names such as total_score.

Question 30Software programming

Which Python statement correctly reads a line of text typed by the user and stores it in a variable called name?

  1. name = input() Correct answer.
  2. name = print()
  3. name == input()
  4. input(name)

Explanation

The input() function returns the typed text as a string, and assignment with = stores that returned value in name. Writing the variable on the left of = is required to capture the result.

Question 31Software programming

A list called scores contains integers. Which expression gives the number of items stored in the list?

  1. len(scores) Correct answer.
  2. scores.length
  3. scores.count
  4. size(scores)

Explanation

The built-in len() function returns the number of elements in a sequence such as a list. So len(scores) evaluates to the count of stored scores.

Question 32Software programming

What does the expression "Digital"[0] return in Python?

  1. An IndexError
  2. "Digital"
  3. "D" Correct answer.
  4. "g"

Explanation

Python strings are indexed from 0, so index 0 refers to the first character. The first character of "Digital" is "D".

Question 33Software programming

Which Python keyword begins a block of code that runs only when a condition evaluates to True?

  1. if Correct answer.
  2. for
  3. def
  4. while

Explanation

The if keyword introduces a conditional block whose body executes only when the tested condition is True. The other keywords start loops or function definitions.

Question 34Software programming

A program stores the string "42" in a variable and needs its numeric value for arithmetic. Which expression produces the integer 42?

  1. float("42")
  2. "42" + 0
  3. str(42)
  4. int("42") Correct answer.

Explanation

The int() function converts a string of digits into an integer, giving 42. This allows arithmetic to be performed on the value.

Question 35Software programming

Consider this code: x = 5 y = 2 result = x / y What is the value and type of result in Python 3?

  1. 3, an int
  2. 2.5, a str
  3. 2, an int
  4. 2.5, a float Correct answer.

Explanation

The single slash / performs true division in Python 3 and always returns a float. Five divided by two is 2.5, stored as a float.

Question 36Software programming

A programmer writes: for i in range(2, 10, 3): print(i) Which numbers are printed?

  1. 2, 5, 8 Correct answer.
  2. 2, 3, 4, 5, 6, 7, 8, 9
  3. 2, 4, 6, 8
  4. 3, 6, 9

Explanation

range(start, stop, step) begins at 2, stops before 10, and increases by 3 each time. The generated values are 2, 5, and 8.

Question 37Software programming

A password check should accept a value only when it is at least 8 characters long. Given the string pw, which condition is correct?

  1. len(pw) == 8
  2. len(pw) <= 8
  3. len(pw) > 8
  4. len(pw) >= 8 Correct answer.

Explanation

"At least 8" includes exactly 8, so the comparison must be >= 8. Using > 8 would reject valid eight-character passwords.

Question 38Software programming

A function is defined as: def greet(name, greeting="Hello"): return greeting + ", " + name What does greet("Ana") return?

  1. Hello, greeting
  2. An error, because greeting is missing
  3. Hello, Ana Correct answer.
  4. greeting, Ana

Explanation

The parameter greeting has a default value of "Hello", so omitting it uses that default. The function then concatenates "Hello", a comma and space, and "Ana".

Question 39Software programming

A list called items holds several values. Which expression returns the last element of the list?

  1. items[len(items)]
  2. items[0]
  3. items[-1] Correct answer.
  4. items.last

Explanation

Negative indices count from the end of a Python sequence, so items[-1] refers to the final element. This works regardless of the list length.

Question 40Software programming

A program must keep asking for a number until the user enters a value greater than zero. Which loop structure fits this requirement?

  1. A while loop testing the entered number Correct answer.
  2. A for loop over range(0, 1)
  3. A single if statement testing the number
  4. A function called once at the start

Explanation

A while loop re-tests its condition after each iteration, so it can repeat until the entered number exceeds zero. The number of attempts is unknown in advance, which suits while rather than for.

Question 41Software programming

Consider this code: def add_one(n): n = n + 1 x = 4 add_one(x) print(x) What is printed?

  1. None
  2. An error is raised
  3. 5
  4. 4 Correct answer.

Explanation

The function changes only its local parameter n; it does not return a value or modify x. Because integers are immutable and the result is not assigned back, x remains 4.

Question 42Software programming

A 2D list grid represents a table where grid[row][col] holds each cell. A programmer wants the value in the third row, second column, counting from 1. Which expression is correct?

  1. grid[1][2]
  2. grid[2][1] Correct answer.
  3. grid[3][2]
  4. grid[2][2]

Explanation

Because indexing starts at 0, the third row is index 2 and the second column is index 1. The correct access is therefore grid[2][1].

Question 43Software programming

A list called nums contains integers. Which expression builds a new list containing only the values greater than 10?

  1. [for n in nums if n > 10]
  2. nums.filter(n > 10)
  3. [n for n in nums if n > 10] Correct answer.
  4. [n if n > 10 for n in nums]

Explanation

A list comprehension places the output expression first, then the for clause, then an optional if filter. This form keeps only elements greater than 10 in a new list.

Question 44Software programming

A programmer wants to swap the values of two variables a and b in Python. Which sequence correctly performs the swap?

  1. a, b = b, a Correct answer.
  2. a = b, b = a
  3. b = a a = b
  4. a = b b = a

Explanation

Tuple assignment a, b = b, a evaluates the right-hand side first and then assigns both values, so the original values are exchanged. This avoids losing a value through overwriting.

Question 45Software programming

A programmer writes: def find_index(items, target): for i in range(len(items)): if items[i] == target: return i return -1 Which statement best describes the behaviour of this function?

  1. It returns the last index of the target in the list.
  2. It returns the number of times the target occurs.
  3. It returns the first index where the target occurs, or -1 if absent. Correct answer.
  4. It sorts the list before searching.

Explanation

The loop checks elements from index 0 upward and returns immediately on the first match, so the earliest occurrence is returned. If the loop finishes with no match, -1 signals absence.

Question 46Software programming

A sorted list of 1000 numbers is searched with binary search. Approximately how many comparisons does the worst case require?

  1. 1000
  2. 100
  3. 500
  4. 10 Correct answer.

Explanation

Binary search halves the search space each step, so the worst case is about log base 2 of n comparisons. Since 2 to the power 10 is 1024, about 10 comparisons suffice for 1000 items.

Question 47Software programming

Consider this code: total = 0 for n in range(1, 6): if n % 2 == 0: total = total + n What is the value of total after the loop finishes?

  1. 4
  2. 9
  3. 15
  4. 6 Correct answer.

Explanation

The loop visits 1 to 5 and adds only the even values, which are 2 and 4. Their sum is 6.

Question 48Software programming

A function is defined as: def process(data): data.append(9) return len(data) nums = [1, 2] result = process(nums) What are the final values of nums and result?

  1. nums is [1, 2, 9] and result is 2
  2. nums is [1, 2, 9] and result is 3 Correct answer.
  3. nums is [9, 1, 2] and result is 3
  4. nums is [1, 2] and result is 2

Explanation

Lists are mutable and passed by reference, so append inside the function modifies the caller's list. After adding 9, nums holds three elements and len returns 3.

Question 49Software programming

A programmer wants to count how many times each word appears in a list. Which structure most directly maps each word to its count?

  1. A dictionary using words as keys and counts as values Correct answer.
  2. A list of the words sorted alphabetically
  3. A 2D list with one row per character
  4. A single integer accumulator

Explanation

A dictionary associates each unique word key with a count value, allowing increments per word. This gives direct lookup of a word's count without scanning a list.

Question 50Software programming

Consider this code: def f(n): if n <= 1: return 1 return n * f(n - 1) What does f(4) return?

  1. 4
  2. 120
  3. 24 Correct answer.
  4. 10

Explanation

This is a recursive factorial: f(4) = 4 * f(3) = 4 * 3 * 2 * 1. The base case returns 1 when n is 1 or less, so the product is 24.