PCEP-30-02 · Question #106
You are writing a Python program that evaluates an arithmetic formular. The formular is described as b equals a multiplied by negative one, then raised to the second power, where a is the value that…
The correct answer is A. b = (-a) ** 2. Option A correctly implements "negate a, then square the result" by placing -a inside parentheses before applying 2, which forces the negation to happen first: (-a)² always yields a non-negative result regardless of a's sign. B is wrong because -2 means "raise to the power of…
Question
Options
- Ab = (-a) ** 2
- Bb = (a) ** -2
- Cb = (-a) * * .2
- Db = -(a) ** 2
How the community answered
(38 responses)- A76% (29)
- B8% (3)
- C3% (1)
- D13% (5)
Explanation
Option A correctly implements "negate a, then square the result" by placing -a inside parentheses before applying **2, which forces the negation to happen first: (-a)² always yields a non-negative result regardless of a's sign.
B is wrong because ** -2 means "raise to the power of negative two" (1/a²), not "negate then square."
C contains a syntax error - the space between * * breaks the exponentiation operator, and .2 is 0.2, not 2.
D is a classic precedence trap: Python's ** operator binds more tightly than unary minus, so -(a) ** 2 is evaluated as -(a²), which negates the result of squaring rather than negating a first - the exact opposite intent.
Memory tip: Think "what gets negated?" - if you want to negate the input, wrap it in parentheses (-a) before the operator; if the minus sign sits outside without parentheses, Python squares first and negates last.
Community Discussion
No community discussion yet for this question.