ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 * 0.1 == 0.3 - 0.2 + 0.1)
- A. False False True
- B. True True False
- C. False True True
- D. False True False
Correct answer: D. False True False
0.1 + 0.2 is 0.30000000000000004 in binary floating point, so the first check fails. Rounding to 10 decimals gives the nearest double to 0.3, so the second is True. 0.3 - 0.2 + 0.1 is 0.19999999999999998, not 0.30000000000000004, so the third is False.
More Python Programming questions
- 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])))
- What is printed? python a = [[1, 2], [3, 4]] b = [row[:] for row in a] c = a[:] a[0][0] = 9 c[1][1] = 7 print(b, c)
- What is printed? python print(len(str(2 64)), (2 64).bitlength(), 2 64 % 9, pow(2, 64, 9))