ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
import cmath
print((-1) ** 0.5 == 1j, -1 ** 0.5, (-1) ** 0.5)
  1. A. True -1.0 (6.123233995736766e-17+1j)
  2. B. False -1.0 (-1+0j)
  3. C. False 1.0 nan
  4. D. False -1.0 (6.123233995736766e-17+1j)

Correct answer: D. False -1.0 (6.123233995736766e-17+1j)

Unary minus binds looser than **, so -1 ** 0.5 is -(1 ** 0.5) = -1.0. Negative bases with fractional exponents give a complex result, and the float rounding of cos(pi/2) makes the real part 6.1e-17 rather than 0, so the result is not exactly 1j.

More Python Programming questions

Exams that ask this topic