ProgrammingHardJEE Advanced · CAT placement
What is printed?
What is printed?
import math print(math.fsum([0.1] * 10) == 1.0, sum([0.1] * 10) == 1.0, math.isqrt(10 ** 30 - 1))
- A. False True 999999999999999
- B. True True 999999999999999
- C. True False 1000000000000000
- D. True True 1000000000000000
Correct answer: B. True True 999999999999999
fsum and the compensated sum() of Python 3.12 and later both round the exact total of ten copies of 0.1 to 1.0. isqrt gives the floor of the square root, and sqrt(10**30 - 1) is just under 10**15.
More Python Programming questions
- What is printed? python print(sorted(['pear', 'Fig', 'apple', 'banana', 'kiwi'], key=lambda s: (len(s), s.lower())))
- What is printed? python print(sorted([('b', 1), ('a', 1), ('c', 2)], key=lambda t: t[1], reverse=True))
- What is printed? python print(max(['abc', 'x', 'yz'], key=len), min(['b', 'B', 'a']))
- What is printed? python from decimal import Decimal from fractions import Fraction print(0.1 + 0.2 == 0.3, Decimal('0.1') + Decimal('0.2')…
- What is printed? python print(1e22, 1e21, 1e16, 1e15, 1e-5, 0.0001)
- What is printed? python print(int(1e16 + 1), 253 + 1 == float(253 + 1), float(253 + 1) == 253)