PCEP-30-02 · Question #140
You create a function to calculate the power of a number by using Python. You need to ensure that the function is documented with comments. You create the following code. Line numbers are included…
The correct answer is C. Line 07 contains an inline comment. D. Lines 01 through 04 will be ignored for syntax checking. C is correct because Line 07 (return x * y # raise x to the y power) places a comment after executable code on the same line - this is the definition of an inline comment in Python. The interpreter executes return x y and ignores everything from # onward. D is correct because…
Question
Options
- AThe string in Line 06 will be interpreted as a comment.
- BThe pound sign (#) is optional for lines 02 and 03.
- CLine 07 contains an inline comment.
- DLines 01 through 04 will be ignored for syntax checking.
How the community answered
(21 responses)- A14% (3)
- B10% (2)
- C76% (16)
Explanation
C is correct because Line 07 (return x ** y # raise x to the y power) places a comment after executable code on the same line - this is the definition of an inline comment in Python. The interpreter executes return x ** y and ignores everything from # onward.
D is correct because Lines 01–04 all begin with #, making them full-line comments. Python's interpreter skips them entirely during parsing and syntax checking - they exist only for human readers.
Why A is wrong: The # on Line 06 is inside double quotes, making it part of a string literal, not a comment. Python only treats # as a comment delimiter when it appears outside of strings, parentheses-enclosed expressions, etc.
Why B is wrong: The # is required for a line to be treated as a comment. Removing it from Lines 02–03 would cause Python to try to parse x is the base as code, resulting in a syntax error.
Memory tip: Think of Python comments as "hash-gated" - the # must be free (outside quotes, not assigned) to open the gate. A # trapped inside a string is just another character, and a # missing from a comment line turns poetry into broken code.
Community Discussion
No community discussion yet for this question.