ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
import math
print(math.sqrt(16), math.sqrt(2) ** 2 == 2, math.isqrt(2) ** 2 == 2, math.pow(2, 0.5) == 2 ** 0.5)
  1. A. 4.0 False False True
  2. B. 4.0 True False True
  3. C. 4 False False True
  4. D. 4.0 False True True

Correct answer: A. 4.0 False False True

sqrt returns a float, so 16 becomes 4.0. The square root of 2 is not exact in binary, so squaring it misses 2, and isqrt(2) is the integer 1, which squares to 1.

More Python Programming questions

Exams that ask this topic