2024 Sep OPPE 2 - Set 1¶
Check If Even Two-Digit Number
Return True if a number is both two-digit (ignoring sign) and even. Covers abs(), chained comparisons, and n % 2 == 0.
Check If Domain is .com or .in
Return True if a domain string ends with .com or .in. Covers str.endswith() with a tuple argument and the importance of including the dot.
Element in Opposite Halves
Check if an element appears in the first half of one list and the second half of the other. Covers lst[:mid], lst[mid:], and the XOR-style flag comparison.
Count Odd 3-Digit Numbers (Ignore None)
Count elements that are not None, are three-digit (ignoring sign), and odd. Covers n is not None guard, abs() for range check, and short-circuit and.
Abbreviate Initials and Sort
Abbreviate all name parts except the surname, then print sorted alphabetically. Full I/O - covers parts[:-1], parts[-1], and sorted().
Shopping List
Three operations on a grocery list - total bill, max quantity item, and sort by total amount. Covers sum(), max(key=), and multi-criteria sorted() with negate-for-descending.
Ubbi Dubbi
Insert "ub" or "dub" alternately before vowels across a multi-line file. File I/O → stdout - covers global counters, print(end=""), and set("aeiou") for O(1) lookup.