ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(-1 ** 2, (-1) ** 2, -1 ** -1, (-1) ** -1)
  1. A. -1.5 -1 -1.0 -1.0
  2. B. -1 1 -1 -1
  3. C. -1 1 -1.0 -1.0
  4. D. -1 1 1.0 2.0

Correct answer: C. -1 1 -1.0 -1.0

The unary minus applies after **, so -1 ** 2 is -1. (-1) ** 2 is 1, and a negative exponent gives a float, so -1 ** -1 is -(1.0) and (-1) ** -1 is -1.0.

More Python Programming questions

Exams that ask this topic