ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 * 0.1, 0.1 * 0.1 == 0.01, round(0.1 * 0.1, 2) == 0.01, 10 * 0.1 * 0.1 * 10 == 1)
- A. 0.01 False True True
- B. 0.010000000000000002 True True True
- C. 0.010000000000000002 False True True
- D. 0.010000000000000002 False False True
Correct answer: C. 0.010000000000000002 False True True
The product of 0.1 and 0.1 misses 0.01 by one unit in the last place, but rounding to two places fixes it. Multiplying by 10 at each end here happens to land exactly on 1.
More Python Programming questions
- What is printed? python print(len(str(777)), 777 % 1000, str(777)[-3:], int(str(777)[:3]))
- What is printed? python def rpn(tokens): st = [] for t in tokens: if t in ('+', '-', '', '/'): b = st.pop() a = st.pop() if t == '+'…
- What is printed? python def ceildiv(a, b): return -(-a // b) print(ceildiv(7, 2), ceildiv(-7, 2), ceildiv(6, 3), ceildiv(1, 5))
- What is printed? python def atmost(a, k): l = s = c = 0 for r, x in enumerate(a): s += x while s > k: s -= a[l] l += 1 c += r - l + 1…
- What is printed? python from itertools import accumulate a = [3, 1, 4, 1, 5, 9, 2] print(list(accumulate(a, max)), list(accumulate(a…
- What is printed? python def comps(n, edges): p = list(range(n)) def find(x): while p[x] != x: p[x] = p[p[x]] x = p[x] return x cnt = n for…