2024 Sep OPPE 1 - Set 2¶
Section 1 · Question 1
Check Positive Odd or Negative Even
Two compound conditions joined by or. Covers sign checks, parity, and Python's modulo behaviour for negatives.
Section 1 · Question 2
String Within and Has Double Quotes
Check outer and inner double quotes. Covers s[1:-1] interior slicing, startswith(), and length guards.
Section 1 · Question 3
Replace Middle with N Times Middle
Expand the middle element of an odd-length tuple into n copies. Covers (val,)*n and tuple slicing.
Section 2 · Question 1
Count Positive Integers Ignoring None
Count elements that are not None and greater than zero. Covers is not None and short-circuit evaluation.
Section 2 · Question 2
Sum and Absolute Difference Alternately
Alternate between sum and abs diff for n comma-separated pairs. Full I/O - covers 1-indexed parity and split(",").
Section 3 · Question 1
Matrix Walk
Traverse a square matrix in L, Z, or O shape. Covers list comprehension traversals and lambda dispatch dicts.
SolvedSection 3 · Question 2
X Pattern
Print an X-shaped pattern using \ and /. Full I/O - covers converging/diverging inner-space formulas.