ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(round(1.0000000000000002, 15) == 1, 1.0000000000000002 == 1, 1.0000000000000002 - 1 == 2.220446049250313e-16)
- A. False True False
- B. True True True
- C. True False False
- D. True False True
Correct answer: D. True False True
Rounding to 15 places removes the tiny excess, so the first check is True. The literal is one ulp above 1, so it is not equal to 1, and its excess is exactly 2**-52.
More Python Programming questions
- What is printed? python s = 'hello world' print(s.title().split()[1][::-1], s.rsplit(' ', 1)[0], s.count('o', 5))
- What is printed? python print(int(0.1 10), round(0.1 10, 10) == 1, 0.1 10 == 1)
- What is printed? python print(abs(-0.0), abs(-3), abs(True), abs(-2 63))
- What is printed? python print(bool(0.0 or 0j), bool(0j or 1j), 0j == 0, 1j 1j)
- What is printed? python print([x for x in range(5) if x % 2], [x for x in 'a1b2' if x.isdigit()], {x % 3 for x in range(6)})
- What is printed? python print(str(()), str([()]), repr(('a',)), str(('a', 1)))