ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
import cmath print((-1) ** 0.5 == 1j, -1 ** 0.5, (-1) ** 0.5)
- A. True -1.0 (6.123233995736766e-17+1j)
- B. False -1.0 (-1+0j)
- C. False 1.0 nan
- 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
- What is printed? python print((-7) % 3, 7 % -3, (-7) % -3, -7 % 3 2)
- What is printed? python print(-6 & 0xFF, -6 | 3, -6 ^ -3, ~-6 >> 1)
- What is printed? python print(len('ab' 3 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)
- What is printed? python print(-7 // 2, -7 % 2, -7 // 2 2 + -7 % 2)
- What is printed? python print(7 // -2, -7 // 2, 7 % -2, divmod(-7, -2))
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(0.5 + 1e-16))