nerdexam
Python_Institute

PCEP-30-02 · Question #272

What is the expected output of the following code? ``python print(chr(ord('p') + 3)) ``

The correct answer is D. s. ord('p') returns 112 (the ASCII value of lowercase 'p'), and adding 3 gives 115; chr(115) converts that back to 's', making D correct. Choices A ('q'), B ('r'), and C ('t') correspond to offsets of +1, +2, and +4 respectively - common off-by-one or off-by-two errors that arise…

Question

What is the expected output of the following code?
print(chr(ord('p') + 3))

Options

  • Aq
  • Br
  • Ct
  • Ds

How the community answered

(32 responses)
  • A
    3% (1)
  • B
    6% (2)
  • C
    6% (2)
  • D
    84% (27)

Explanation

ord('p') returns 112 (the ASCII value of lowercase 'p'), and adding 3 gives 115; chr(115) converts that back to 's', making D correct.

Choices A ('q'), B ('r'), and C ('t') correspond to offsets of +1, +2, and +4 respectively - common off-by-one or off-by-two errors that arise from miscounting or miscalculating the addition.

Memory tip: The alphabet is sequential in ASCII - 'a' through 'z' are contiguous values - so ord(char) + n simply moves n letters forward. Count on your fingers: p → q → r → s (three steps).

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice