Jan 2026 Python OPPE 1 · Pattern and Solution Guide
750 words
4 min read
2026-08-02T00:00:00.000Z
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
Compact worked guide to the seven student-authorized archived Jan 2026 OPPE 1 questions. # Jan 2026 Python OPPE 1 · Pattern and Solution Guide > **Archived assessment, for preparation and review only.** The screenshots are from the completed January 2026 term.

Jan 2026 Python OPPE 1 · Pattern and Solution Guide
Archived assessment, for preparation and review only. The screenshots are from the completed January 2026 term. Do not open this guide or use an LLM during a live graded assessment.
How to use this in the next few hours
For each pattern: hide the code, write the input/output contract, name the data structure, solve for one example by hand, then code. Run tests only after tracing once. If stuck for ten minutes, read only the key idea, retry, and inspect the solution last.
1 · Zigzag number grid
Pattern: nested loops plus row parity. Odd-numbered human rows are even Python indices.
pythonn = int(input()) for row in range(n): values = range(1, n + 1) if row % 2 == 0 else range(n, 0, -1) print(*values)
Common mistake: changing the numbers across rows when the archived question repeats
1..n or n..1 on every row.2 · Flight tracking system
Pattern: one pass to aggregate records, then deterministic tie-breaking. A route is the tuple
(origin, destination).pythondef on_time_percentage(flights): if not flights: return 0.0 count = sum(delay < 15 for _, _, delay in flights) return round(100 * count / len(flights), 2) def most_delayed_route(flights): delays = {} for origin, destination, delay in flights: delays.setdefault((origin, destination), []).append(delay) return max(delays, key=lambda route: sum(delays[route]) / len(delays[route])) if delays else None def busiest_airport(flights): counts = {} for origin, destination, _ in flights: counts[origin] = counts.get(origin, 0) + 1 counts[destination] = counts.get(destination, 0) + 1 return min(counts, key=lambda airport: (-counts[airport], airport)) if counts else None def total_delay_hours(flights): return round(sum(delay for _, _, delay in flights) / 60, 2) def track_flights(flights): return { "on_time_percentage": on_time_percentage(flights), "most_delayed_route": most_delayed_route(flights), "busiest_airport": busiest_airport(flights), "total_delay_hours": total_delay_hours(flights), }
Why the tie rules work: dictionaries preserve first insertion order, so
max keeps the first route when averages tie; the (negative count, name) key explicitly makes alphabetical order win for airports.3 · Group and sum by key
Pattern: parse → accumulate → sort → format.
pythonn = int(input()) totals = {} for _ in range(n): key, raw_values = input().split(":", 1) totals[key] = totals.get(key, 0) + sum(map(float, raw_values.split(","))) for key in sorted(totals): total = totals[key] print(f"{key}:{total:g}")
Use
split(":", 1) so only the first separator divides key from values. If the question guarantees integers, use int instead of float.4 · Largest zero-sum subarray
Pattern: equal prefix sums mark a zero-sum interval. Store the first index of each prefix sum to maximize length and preserve the earliest tie.
pythondef largest_zero_sum_subarray(nums): first = {0: -1} prefix = 0 best_start = best_length = 0 for index, value in enumerate(nums): prefix += value if prefix in first: start = first[prefix] + 1 length = index - first[prefix] if length > best_length: best_start, best_length = start, length else: first[prefix] = index return nums[best_start:best_start + best_length]
Complexity:
O(n) time and O(n) space. Updating only on >—not >=—keeps the earlier answer on a tie.5 · Move even positions to the end, reversed
Pattern: clarify whether “even indices” means Python indices
0,2,4... or human positions 2,4,6.... The archived function name uses Python indices.pythondef move_even_indices_to_end_reversed(t): return t[1::2] + t[::2][::-1]
Trace with indices written above the tuple before coding. This avoids the most common off-by-one error.
6 · Sum of ends divisible by k
Pattern: direct Boolean expression plus input-precondition awareness.
pythondef is_sum_of_ends_divisible_by_k(nums, k): return (nums[0] + nums[-1]) % k == 0
This assumes the promised non-empty list and non-zero
k. Do not add behavior the contract did not request unless input validation is explicitly required.7 · String repeated three times
Pattern: guard the length, compute one block, compare repetitions.
pythondef is_repeated_thrice(s): if len(s) % 3 != 0: return False block_size = len(s) // 3 block = s[:block_size] return s == block * 3
Ask whether the empty string should count. Mathematically this implementation returns
True; add if not s: return False only if the specification requires a non-empty repeated block.Final recall checklist
- Can I translate human positions to Python indices?
- Can I choose between a direct expression, slicing, a loop, and a dictionary?
- Can I state the tie-break before writing
minormax? - Can I explain why repeated prefix sums identify a zero-sum interval?
- Can I parse a line in stages and format exactly what the prompt requests?
- Did I test empty, one-element, tie, and boundary cases allowed by the contract?