ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
import math print(math.isclose(0.1 + 0.2, 0.3), math.isclose(1e-10, 0), math.isclose(1e-10, 0, abs_tol=1e-9), math.inf > 10 ** 400)
- A. True True True True
- B. True False True True
- C. False False True True
- D. True False True OverflowError
Correct answer: B. True False True True
isclose uses a relative tolerance by default, which can never succeed against 0, so an absolute tolerance is needed there. Comparing a float with a huge int is done exactly, and inf exceeds every int.
More Python Programming questions
- What is printed? python a = 0.1 + 0.2 print(f"{a:.20f}"[:6], a == 0.3, round(a, 15) == round(0.3, 15), str(a) == "0.30000000000000004"…
- What is printed? python print(10 / 4, 10 // 4, -10 // 4, 10 % -4, 2 -2, 7 // 2.0)
- What is printed? python s = "abcdefghij" print(s[2:8:3], s[-2:-9:-3], s[8:2:3] == "", s[::4] + s[1::4])
- What is printed? python L = list(range(10)) L[2:8:2] = "XYZ" del L[-3:] L[len(L):] = [99] print(L)
- What is printed? python d = {"b": 2, "a": 1} print(sorted(d.items()), sorted(d, key=d.get), list(reversed(sorted(d.values()))), {d, "a"…
- What is printed? python from collections import Counter c = Counter(a=3, b=1) c.update("aab") c.subtract({"b": 5}) print(c["a"], c["b"]…