ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
total = 0.0
for _ in range(10):
total += 0.1
print(total, total == 1.0, sum([0.1] * 10) == 1.0)- A. 1.0 True True
- B. 0.9999999999999999 False False
- C. 0.9999999999999999 False True
- D. 1.0 True False
Correct answer: C. 0.9999999999999999 False True
A plain loop accumulates rounding error, leaving 0.9999999999999999. The built-in sum() uses compensated summation since Python 3.12 and returns exactly 1.0 here.
More Python Programming questions
- Which of these is the best way to build a string from n pieces in CPython, and why?
- A program makes 10^5 membership checks of the form x in visited, where visited holds 10^5 items. Which statement is correct?
- What is printed? python def cnt(a, k): p, l, res = 1, 0, 0 for r, x in enumerate(a): p = x while l <= r and p >= k: p //= a[l] l += 1 res…
- What is printed? python g = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] n, m = 3, 3 P = [[0] (m + 1) for in range(n + 1)] for i in range(n): for j…
- What is printed? python def splits(a): total = sum(a) s = 0 c = 0 for x in a[:-1]: s += x if 2 s == total: c += 1 return c…
- What is printed? python from collections import deque def zeroone(n, edges, src): adj = [[] for in range(n)] for u, v, w in edges…