nerdexam
Python_Institute

PCEP-30-02 · Question #281

What is the expected output of the following code? print(chr(ord('z') - 2))

The correct answer is A. x. Option A is correct because ord('z') returns 122 (the ASCII value of 'z'), subtracting 2 gives 120, and chr(120) resolves to 'x' - two positions before 'z' in the alphabet. Why the distractors are wrong: B (y) would result from subtracting only 1 (ord('z') - 1 = 121 = 'y'), not…

Question

What is the expected output of the following code? print(chr(ord('z') - 2))

Options

  • Ax
  • By
  • Ca
  • Dz

How the community answered

(42 responses)
  • A
    81% (34)
  • B
    12% (5)
  • C
    5% (2)
  • D
    2% (1)

Explanation

Option A is correct because ord('z') returns 122 (the ASCII value of 'z'), subtracting 2 gives 120, and chr(120) resolves to 'x' - two positions before 'z' in the alphabet.

Why the distractors are wrong:

  • B (y) would result from subtracting only 1 (ord('z') - 1 = 121 = 'y'), not 2.
  • C (a) has no arithmetic relationship to this expression; it's a common trap for students who confuse "opposite of z" with "2 back from z."
  • D (z) would only be correct if there were no subtraction at all - i.e., chr(ord('z')).

Memory tip: Think of ord() as "order number" (it gives a character's position in the ASCII table) and chr() as the reverse. Subtracting from ord('z') is like stepping backwards through the alphabet - subtract 2, land on 'x'.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice