ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
import math print(math.isclose(0.1 + 0.2, 0.3), math.isclose(1e-12, 0), math.isclose(1e-12, 0, abs_tol=1e-9))
- A. True False True
- B. False False True
- C. True True True
- D. True False False
Correct answer: A. True False True
isclose uses relative tolerance by default, so a tiny value can never be close to 0 without an absolute tolerance. Passing abs_tol=1e-9 makes it True.
More Python Programming questions
- What is printed? python print(int('١٢٣') + 1, 'ß'.upper(), 'Dž'.lower(), len('ß'.upper()))
- What is printed? python total = 0.0 for in range(10): total += 0.1 print(total, total == 1.0, sum([0.1] 10) == 1.0)
- 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…