Predict the output
What does this print?
import math
n = 10 ** 30 + 1
print(int(math.sqrt(n)) ** 2 <= n, math.isqrt(n) ** 2 <= n)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A True True
Right: both stay at or below n here, though float sqrt can be off for other huge values.
Floating point is risky for very large integers in general, which is why the page's solution searches with exact integer squares.
Why not the others?
- B False True. Here the float result happens to round to exactly 10¹⁵.
- C True False.
math.isqrtis exact and never overshoots.