ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(float(10 ** 16 + 1) == 10 ** 16, 10 ** 16 + 1 == float(10 ** 16 + 1))
- A. False False
- B. True False
- C. False True
- D. True True
Correct answer: B. True False
Above 2**53 doubles are spaced by 2, so 10**16 + 1 rounds to 10**16 as a float. The int comparison is exact, so 10**16 + 1 is not equal to the float.
More Python Programming questions
- What is printed? python x = 0 def f(): global x x += 1 return x print(f() + f() 10, x)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 0.1 == 0.3 - 0.2 + 0.1)
- What is printed? python nums = [3, 1, 2] nums2 = sorted(nums, reverse=True) nums.sort() print(nums, nums2, nums is sorted(nums))
- What is printed? python nums = [13, 22, 5, 31, 8, 3] print(sorted(nums, key=lambda x: x % 10), sorted(nums, key=lambda x: x % 10…
- What is printed? python def gen(): yield 1 return 5 yield 2 it = gen() print(list(it), next(it, 'done'))
- What is printed? python from itertools import accumulate print(list(accumulate([2, 3, 4], lambda a, b: a b)), list(accumulate([1, -1, 2])))