ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 * 3 != 0.3, abs(0.1 * 3 - 0.3) < 2**-52, abs(0.1 * 3 - 0.3) < 2**-54)
- A. True False False
- B. False True True
- C. True True False
- D. True True True
Correct answer: C. True True False
0.1 * 3 is one unit above 0.3, which is about 5.55e-17. That is smaller than 2**-52 but not smaller than 2**-54, so a tolerance this tight fails.
More Python Programming questions
- What is printed? python print(bin(255)[2:].rjust(10, '0'), int('0b' + '1' 8, 2) == 255, int('11111111', 2) + 0 == 255)
- What is printed? python s = 'hello world' print(s.count('o'), s.index('o', 5), s.title().split()[1][::-1])
- What is printed? python print(list(reversed(range(3))), list(range(3))[::-1] == list(reversed(range(3))), list(range(3, 0, -1)))
- What is printed? python print('Python'[::2], 'Python'[1::2], 'Python'[-2::-2])
- What is printed? python x = 3.0 print(x.isinteger(), (3.5).isinteger(), int(x) is x, type(int(x)).name)
- What is printed? python print(round(1e-20, 25) == 1e-20, round(123.456, 10), round(0.5 + 1e-17, 0))