ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
x = 10 ** 16 print(float(x) == x, float(x + 1) == x, x + 1.0 == x, (x + 1) - x)
- A. True True True 1
- B. True False True 1
- C. True True False 1
- D. True True True 0
Correct answer: A. True True True 1
10**16 is exact in a double, so the first comparison is True. float(x + 1) rounds to the even neighbour 10**16, and x + 1.0 also rounds back to 10**16. The integer subtraction is exact, giving 1.
More Python Programming questions
- What is printed? python print('%5s|%-5s|' % ('ab', 'cd'))
- What is printed? python print(len('%-8.3f|' % 3.14159), len('%08.3f' % -3.14159), '%08.3f' % -3.14159)
- What is printed? python import math print(math.prod([]), math.prod(range(1, 6)), math.lcm(range(1, 6)), math.lcm())
- What is printed? python print(list('ab') + ['c'] 2, 'ab' + 'c' 2, ('a',) 2)
- What is printed? python print(10 18 // 7 7 + 10 18 % 7 == 10 18, (-10 18) // 7 7 + (-10 18) % 7 == -10 18, -10 18 % 7 == (-10) 18 % 7)
- What is printed? python from bisect import bisectleft, bisectright a = [1, 2, 2, 2, 3] print(bisectleft(a, 2), bisectright(a, 2)…