ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 + 0.2 == 0.3, abs(0.1 + 0.2 - 0.3) < 1e-9)
- A. False False
- B. True True
- C. True False
- D. False True
Correct answer: D. False True
0.1 and 0.2 have no exact binary form, so their sum is 0.30000000000000004, not 0.3, and == is False. Comparing within a small tolerance (or using math.isclose) gives True.
More Python Programming questions
- What is printed? python def outer(): n = 0 def inc(): nonlocal n n += 1 return n return inc c = outer() c(); c() print(c())
- What is printed? python print([1, 2, 3], sep="-", end="!n")
- What is printed? python print("%d items" % 3.9, int("0x1A", 16))
- What is printed? python def f(a, b=2, c, d=4): return a + b + sum(c) + d print(f(1, 3, 5, 7, d=1))
- What is printed? python class A: def show(self): return "A" class B(A): def show(self): return "B" + super().show() print(B().show())
- What is printed? python x = [1, 2, 3] y = x[:] y[0] = 9 z = x z[1] = 8 print(x)