ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import math n = 10 ** 30 - 1 print(math.isqrt(n), int(n ** 0.5))
- A. 1000000000000000 999999999999999
- B. 999999999999999 1000000000000000
- C. 999999999999999 999999999999999
- D. 1000000000000000 1000000000000000
Correct answer: B. 999999999999999 1000000000000000
isqrt is exact integer arithmetic and gives 10^15 - 1. n ** 0.5 converts n to a float first, and 10^30 - 1 rounds to 10^30 as a float, so the square root comes out as exactly 1e15.
More Python Programming questions
- What is printed? python print(2 53 + 1 == float(2 53 + 1))
- What is printed? python import io s = io.StringIO("abcn") print(repr(s.readline()), repr(s.readline()))
- What is printed? python data = "2n10 20n30n" it = iter(data.split()) n = int(next(it)) arr = [int(next(it)) for in range(n)] print(arr…
- What is printed? python from operator import itemgetter rows = [('b', 2, 'x'), ('a', 2, 'y'), ('c', 1, 'z')] print([r[0] for r in…
- What is printed? python import bisect print(bisect.bisect([1, 2, 2, 5], 2))
- What is printed? python try: sorted([3, 'a']) except TypeError as e: print(e)