ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(int(1e16 + 1), 2**53 + 1 == float(2**53 + 1), float(2**53 + 1) == 2**53)
- A. 10000000000000002 True False
- B. 10000000000000000 False True
- C. 10000000000000000 True True
- D. 10000000000000001 False True
Correct answer: B. 10000000000000000 False True
1e16 + 1 lies exactly between two doubles spaced by 2, and round-half-to-even picks 1e16. Converting 2**53 + 1 to float also rounds to 2**53, so the exact int comparison is False and the float comparison is True.
More Python Programming questions
- What is printed? python print(pow(10, 18, 7), (-3) 3 % 7, pow(-3, 3, -7), -3 3 % 7)
- What is printed? python print('%.3s|%5.1s|' % ('abcdef', 'xyz'))
- What is printed? python print('straße'.casefold() == 'strasse', 'straße'.lower() == 'strasse', 'Straße'.casefold())
- What is printed? python print('x'.removeprefix('xx'), 'hello'.removesuffix('llo'), 'abc'.removeprefix(''))
- What is printed? python print(str.maketrans('ab', 'xy', 'c'), 'abcabc'.translate(str.maketrans('ab', 'xy', 'c')))
- What is printed? python print(sorted(['10', '9', '100', '2']), sorted(map(int, ['10', '9', '100', '2'])))