Programming in a High-Level Language (Python/C++)
This domain tests syntax and semantics in Python or C++: data types, operators, input/output, control flow, functions and debugging.
Language mechanics
High-level languages are portable and readable. Python uses indentation to delimit blocks, dynamic typing and concise syntax; C++ uses braces, semicolons, explicit declarations and a compiler. Both support variables, operators, selection, iteration, functions and input/output. Python’s input() returns a string, so numeric input needs int() or float(). C++ uses cin >> and cout <<, with variables declared before use.
Indexing and evaluation
Python sequences are zero-indexed: in s = 'ABC', s[0] is 'A' and s[-1] is 'C'. Integer division // discards the fractional part; % gives the remainder. Operator precedence matters: ** before *, /, //, %, then + and −; comparisons and logical operators follow.
Worked example
Evaluate 7 // 2 * 3 + 2 ** 3 in Python. Exponentiation first: 2 ** 3 = 8. // and * have equal precedence and associate left to right: 7 // 2 = 3; 3 * 3 = 9. Then 9 + 8 = 17. If the expression were 7 // (2 * 3) + 8, it would be 7 // 6 + 8 = 1 + 8 = 9. Parentheses change the grouping.
C++ contrast: int a = 7 / 2; stores 3, but double b = 7.0 / 2; stores 3.5. Mixing int and double promotes to double.
Traps that cost marks
- Forgetting Python’s colon and indentation after if/for/while.
- Expecting input() to return a number.
- Using a list index equal to its length; valid indexes stop at length−1.
- Omitting semicolons or declaration types in C++.