ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(0.1 + 0.2 - 0.3, 0.3 - 0.1 - 0.2, 1 / 49 * 49, 1 / 10 * 10)
- A. 5.551115123125783e-17 -2.7755575615628914e-17 0.9999999999999999 1.0
- B. 5.551115123125783e-17 -2.7755575615628914e-17 1.0 1.0
- C. 0.0 0.0 1.0 1.0
- D. 5.551115123125783e-17 2.7755575615628914e-17 0.9999999999999999 0.0
Correct answer: A. 5.551115123125783e-17 -2.7755575615628914e-17 0.9999999999999999 1.0
Each decimal is an approximation, so the residuals are tiny and the order of operations changes their sign. 1/49 has no exact binary form, so multiplying back by 49 can fall just below 1.
More Python Programming questions
- What is printed? python import bisect a = [10, 9, 2, 5, 3, 7, 101, 18] tails = [] for x in a: i = bisect.bisectleft(tails, x) if i ==…
- What is printed? python from itertools import product print(list(product('ab', repeat=2)), list(product([0, 1], 'x')))
- What is printed? python d = {'pen': 3, 'cap': 5, 'ink': 3, 'box': 1} print(sorted(d.items(), key=lambda kv: (-kv[1], kv[0]))[:3])
- What is printed? python from collections import deque n = 4 edges = [(0, 2), (1, 2), (2, 3), (0, 3)] indeg = [0] n adj = [[] for in…
- What is printed? python def cnt(xs, T): xs = sorted(xs) lo, hi, total = 0, len(xs) - 1, 0 while lo < hi: if xs[lo] + xs[hi] <= T: total +=…
- What is printed? python def knap(items, cap): dp = [0] (cap + 1) for w, v in items: for c in range(cap, w - 1, -1): dp[c] = max(dp[c]…