PCEP study materials
PCEP study resources

PCEP: Computer Programming and Python Fundamentals

PCEP · Work through your exam, one topic at a time.

All guide sections

Computer Programming and Python Fundamentals

What this domain covers

PCEP's first domain checks whether you can read and write short Python snippets built from literals, variables, operators and built-in I/O. Questions are usually single-line expressions where precedence, type or a subtle naming rule decides the answer.

Core rules

  • Identifiers are case-sensitive, may contain letters, digits and underscores, but cannot begin with a digit. Keywords such as class, def and None are reserved. myVar, _x2 and 总量 are legal; 2x and my-var are not.
  • Literals include integers (0, 1_000), floats (2.0, 1e3), strings, booleans (True, False) and None.
  • Operators: + - * / // % **. / always returns a float; // floors toward negative infinity, so -7 // 2 == -4; % follows the sign of the divisor, so -7 % 2 == 1; ** binds tighter than unary minus, so -2 ** 2 == -4.
  • Precedence roughly: **, unary, * / // %, + -, comparisons, not, and, or. Parentheses override it.
  • input() always returns a str; convert with int() or float() before arithmetic. print(a, b, sep=",", end="") controls separators and line endings.

Worked example

x = input() and the user types 3; then y = 2; print(x * y) outputs 33, not 6. x is the string "3", and str * int repeats the string. Fix it with x = int(input()).

Traps

  • = assigns, == compares; using = in an if is a SyntaxError.
  • 1 + 2.0 yields 3.0; mixing int and float promotes to float.
  • bool("") is False, but bool("0") is True.
  • round(2.5) is 2 (banker's rounding), and int("2.5") raises ValueError.