How to use this practice set

These ten questions cover common programming fundamentals: expressions, conditions, loops, functions, collections, strings and basic algorithm analysis. They use Python 3 so each question has one precise answer. If your course uses another language, translate the idea into its syntax and check details such as integer division and indexing against your course materials.

For each question, decide on an answer before reading the explanation beneath it. Then compare your reasoning, not just your selected option: trace the changing values, identify the rule being tested and notice why a plausible alternative is wrong. If you miss a question, write down the specific rule you need to practise, such as “a slice excludes its end index”, rather than simply recording the question number.

1. Integer division and remainder

This checks whether you can distinguish the quotient from the remainder in Python 3.

A single-best-answer question on division looks like this:

Question 11 mark

What does this code print? print(17 // 5, 17 % 5)

The correct answer is 3 2. Floor division gives the integer quotient: 17 // 5 is 3. The remainder operator gives what is left over: 17 % 5 is 2, since 5 × 3 + 2 = 17. The strongest distractor is 3 3; it incorrectly treats the remainder as the quotient.

Question 1 checks how Python 3 separates an integer quotient from a remainder.

Use the identity dividend = divisor × quotient + remainder to check this sort of result. It also helps catch the mistake of confusing % with percentage.

2. Boolean conditions

This tests how and combines two comparisons: both must be true for the whole expression to be true.

A condition-tracing question looks like this:

Question 21 mark

What does this code print? x = 4 print(x > 2 and x < 4)

The correct answer is False. The first comparison, 4 > 2, is true, but the second, 4 < 4, is false because the values are equal. With and, one false condition makes the full expression false. The strongest distractor is True; it checks only the first comparison and ignores the second.

Question 2 tests the truth value of a compound condition.

When tracing a compound condition, evaluate each comparison separately before applying and or or. This avoids guessing from the overall shape of the expression.

3. A counted loop

This checks the start and stop behaviour of Python’s range function.

A loop-tracing question looks like this:

Question 31 mark

What value is printed? total = 0 for i in range(1, 5): total += i print(total)

The correct answer is 10. range(1, 5) produces 1, 2, 3 and 4; the stop value 5 is excluded. Adding those values gives 10. The strongest distractor is 15, which comes from mistakenly including 5 as well.

Question 3 checks which values a range-based loop visits.

For a short loop, list each value taken by the loop variable and update the accumulator once per value. In longer code, a small trace table with columns for i and total makes the same process manageable.

4. List aliasing

This tests whether a second variable refers to a new list or to the same list object.

A list-mutation question looks like this:

Question 41 mark

What does this code print? a = [1, 2] b = a b.append(3) print(a, b)

The correct answer is [1, 2, 3] [1, 2, 3]. The assignment b = a does not copy the list; both names refer to the same object. Calling append through b therefore changes the list also seen through a. The strongest distractor is [1, 2] [1, 2, 3], which assumes that assignment automatically makes a copy.

Question 4 checks what happens when two names refer to the same list.

The key distinction is between changing a mutable object and assigning a different object to a variable. If you need an independent shallow copy of this list, b = a.copy() would create one.

5. Function return values

This checks the difference between a function’s local parameter and the caller’s variable.

A function-tracing question looks like this:

Question 51 mark

What does this code print? def add_two(x): x = x + 2 return x n = 3 print(add_two(n), n)

The correct answer is 5 3. Inside the function, the local parameter x becomes 5 and that value is returned. The assignment does not reassign n in the caller, so n remains 3. The strongest distractor is 5 5; it confuses changing the local parameter with changing the caller’s variable.

Question 5 tests a returned value and the unchanged caller variable.

When a question involves a function, trace its body with the argument value, then return to the calling line and substitute the returned value. Keep local names and caller names distinct even when a function mutates an object.

6. String slicing

This tests Python’s zero-based string indexing and the excluded end of a slice.

A string-indexing question looks like this:

Question 61 mark

What is the value of 'coding'[1:4]?

The correct answer is odi. The characters have indices c=0, o=1, d=2, i=3, n=4, g=5. A slice starting at 1 and stopping at 4 includes indices 1, 2 and 3, but not 4. The strongest distractor is odin, which incorrectly includes the character at the stop index.

Question 6 checks zero-based indexing and an exclusive slice endpoint.

For a slice, mark the start and stop positions before selecting characters. Remembering that the start is included and the stop is excluded resolves many off-by-one errors.

7. Nested loops

This checks how many times the inner body runs when each loop has a fixed range.

A nested-loop question looks like this:

Question 71 mark

How many times does the print statement run? for row in range(3): for col in range(2): print(row, col)

The correct answer is 6. The outer loop has 3 iterations, and for each one the inner loop has 2 iterations, so the body runs 3 × 2 = 6 times. The strongest distractor is 5, which adds the loop lengths instead of counting every pair of iterations.

Question 7 checks how to count executions of a nested loop body.

For nested loops, multiply the iteration counts when each inner loop completes fully for every outer iteration. If a loop’s range depends on a variable, count the inner iterations separately for each outer value instead.

8. Linear search complexity

This tests worst-case analysis for a search that checks items one at a time.

An algorithm-analysis question looks like this:

Question 81 mark

A linear search checks items in an unsorted list from first to last and stops when it finds the target. What is its worst-case time complexity for a list of n items?

The correct answer is O(n). If the target is last or absent, the search may inspect all n items, so the number of checks grows in proportion to n. The strongest distractor is O(log n), which is associated with methods such as binary search that repeatedly narrow a suitable ordered search space; a basic linear search does not do that.

Question 8 tests worst-case time complexity for a linear search.

Complexity describes how work grows as input size grows, not the exact running time for one input. Identify the operation repeated by the algorithm, then ask how many times it can occur in the worst case.

9. Binary search

This tests the precondition that makes binary search’s repeated halving valid.

A search-method question looks like this:

Question 91 mark

Which condition must hold for ordinary binary search on an array to be reliable?

The correct answer is that the array must be sorted by the search key. Binary search compares with a middle element and discards one half based on the ordering; without that order, it cannot safely choose which half to discard. The strongest distractor is the requirement for distinct values: duplicates are permitted, although the exact returned duplicate can depend on the implementation.

Question 9 checks the input condition required for ordinary binary search.

When a question asks you to choose an algorithm, check its preconditions as well as its speed. Applying a fast method to data that violates its assumptions can produce an incorrect result.

10. Filtering a list

This checks the order in which a list comprehension filters values and then transforms them.

A final tracing question looks like this:

Question 101 mark

What is the value of this expression? [x * x for x in range(4) if x % 2 == 0]

The correct answer is [0, 4]. range(4) supplies 0, 1, 2 and 3; the condition keeps the even values 0 and 2, and the expression squares each one. The strongest distractor is [1, 9], which applies the condition to odd rather than even values.

Question 10 checks filtering and transforming values in a list comprehension.

A useful trace is: candidates 0, 1, 2, 3; retained values 0 and 2; transformed values 0 and 4. Separating those stages helps with longer comprehensions too.

Turn mistakes into a focused review

After completing the set, sort errors by the underlying idea: tracing, syntax, data structures or algorithm reasoning. Revisit the relevant topic in your course notes and make a small variation of the missed question. For example, change the loop’s stop value or add one more list mutation, then predict the result and explain the rule. This checks whether you understood the concept rather than memorised one output.

A review view for a learner who has repeatedly missed list and loop questions might look like this:

Where marks go missing
58%List aliasing and mutation8×
67%Loop tracing11×
86%Boolean expressions7×
This view ranks topics by the learner's practice results and recorded appearances.

The most useful next step is specific: explain why the two names share a list, or trace one loop iteration at a time. A reminder created from a repeated missed mark could ask:

Remediation tray

You lost this mark twice: after b = a, what does b.append(3) change, and why does printing a show the appended value too?

Add cardDismiss
This reminder turns a repeated list-aliasing error into one focused recall prompt.

If the same error persists, practise a new example with different values and say the rule aloud before calculating. For algorithm questions, state the precondition and worst case; for code tracing, state the values after each relevant line.

How MySummaries helps

MySummaries lets you build a revision board from your own programming notes and practise from the topics on it. Its generated questions can be marked against that material, while missed points can feed into focused review. Start at portal.mysummaries.app.