ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(0.1 + 0.7 == 0.8, 0.8 - 0.7, 0.3 / 0.1, int(0.3 / 0.1))
- A. True 0.1 3.0 3
- B. False 0.10000000000000009 2.9999999999999996 2
- C. False 0.1 2.9999999999999996 3
- D. False 0.10000000000000009 3.0 2
Correct answer: B. False 0.10000000000000009 2.9999999999999996 2
0.1 + 0.7 rounds to a value slightly above 0.8, and 0.8 - 0.7 exposes the error. 0.3 / 0.1 is just below 3, so int truncates it to 2.
More Python Programming questions
- What is printed? python print(1.0 == 1, 1.5 // 0.5, 1.5 % 0.4, 2.0 -1074 > 0, 2.0 -1075 == 0)
- What is printed? python print(float.fromhex('0x1p-2'), 0.25 == float.fromhex('0x1p-2'), float.fromhex('0x1.8p1'))
- What is printed? python print(divmod(10, 3)[::-1], divmod(-10, 3)[::-1], divmod(10, -3)[::-1])
- What is printed? python print(-5 % 3 == 1, 5 % -3 == -1, -5 // -3, 5 // -3)
- What is printed? python s = 'a-bc d' print(s.replace('-', ' ').replace('', ' ').split(), s.translate({45: None}))
- What is printed? python print('abc'.index('c') + 'abc'.rindex('a'), 'aXbXc'.rsplit('X', 1), 'a b'.title())