Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(0.1 + 0.2 == 0.3, round(2.5), round(3.5))
- A. True 2 4
- B. False 2 4
- C. False 3 4
- D. False 2 3
Correct answer: B. False 2 4
0.1 + 0.2 is 0.30000000000000004 in binary floating point, and round uses banker's rounding (ties go to the even integer), giving 2 and 4.
More Coding Interview Problems questions
- Problem: What does the following print? python a = [1, 2, 3] b = a b += [4] print(a)
- Problem: What does the following print? python print(int('0b101', 0), int('101', 2), 7 // 2 2)
- Problem: What does the following print? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- Problem: What does the following print? python print(len({1, 2, 3} & {2, 3, 4} | {5}))
- Problem: What does the following print? python print('10' < '9', 10 < 9)
- Problem: What does the following print? python print(int('12', 8) + int('0x1f', 16))