ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print((-1) ** 0.5, (-1) ** 2, (-8) ** (1 / 3), -1 ** 0.5)
  1. A. nan 1 nan -1.0
  2. B. (6.123233995736766e-17+1j) 1 (-2+0j) -1.0
  3. C. (6.123233995736766e-17+1j) 1 (1.0000000000000002+1.7320508075688772j) -1.0
  4. D. 1j 1 (-2+0j) 1.0

Correct answer: C. (6.123233995736766e-17+1j) 1 (1.0000000000000002+1.7320508075688772j) -1.0

In Python 3, a negative base raised to a fractional power returns a complex number, so (-1) ** 0.5 is the principal square root i (with a tiny float error). -1 ** 0.5 parses as -(1 ** 0.5) = -1.0.

More Python Programming questions

Exams that ask this topic