ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sum([0.1] * 10) == 1.0, 0.1 * 3 == 0.3)
- A. False True
- B. True False
- C. False False
- D. True True
Correct answer: B. True False
Since Python 3.12, sum() uses compensated summation for floats, so ten 0.1 values add up to exactly 1.0 in Python 3.13. Plain repeated multiplication does not get that help: 0.1 * 3 is 0.30000000000000004, so the second check is False.
More Python Programming questions
- What is printed? python import heapq iv = sorted([(0, 30), (5, 10), (15, 20)]) h = [] for s, e in iv: if h and h[0] <= s…
- What is printed? python from collections import Counter a = [1, -1, 2, -2, 0] cnt = Counter({0: 1}) s = 0 ans = 0 for x in a: s += x ans…
- What is printed? python print(4 & 3 == 0, 6 & 3 == 0)
- What is printed? python print(int(1e23), int(1e20))
- What is printed? python x = [3, 1, 2].sort() print(x, sorted([3, 1, 2]))
- What is printed? python print(min([(1, 'b'), (1, 'a')], key=lambda t: t[0]), max(['aa', 'b', 'cc'], key=len))