ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
a = 0.1 + 0.2
print(f"{a:.20f}"[:6], a == 0.3, round(a, 15) == round(0.3, 15), str(a) == "0.30000000000000004", float.hex(0.5))- A. 0.3000 False True True 0x1.0000000000000p-1
- B. 0.3000 True True True 0x1.0000000000000p-1
- C. 0.3000 False False True 0x1.0000000000000p-1
- D. 0.3000 False True False 0x0.8p+0
Correct answer: A. 0.3000 False True True 0x1.0000000000000p-1
The binary sum is slightly above 0.3, so == fails but rounding both to 15 places matches. str gives the shortest repr that round-trips. float.hex(0.5) is 1.0 x 2^-1.
More Python Programming questions
- 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"]…
- What is printed? python from collections import ChainMap defaults = {"color": "red", "size": 1} user = {"size": 3} cm = ChainMap(user…