Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(round(1.23456, 2), round(-2.5))What is printed?
- A. 1.23 -3
- B. 1.24 -2
- C. 1.23 -2.0
- D. 1.23 -2
Correct answer: D. 1.23 -2
Rounding to two decimals gives 1.23, and round uses banker's rounding so -2.5 becomes -2.
More Coding Interview Problems questions
- Problem: What does the following print? python print(max([], default=-1), sum([]), divmod(-7, 3))
- Problem: What does the following print? python print(2 -1, 7 % -3)
- Problem: What does the following print? python print(sorted([3, 1, 2], key=lambda x: -x)[0]) What is printed?
- Problem: Starting from 3, you may apply two operations: "+1" or "×2". What is the minimum number of operations needed to reach exactly 50?
- Problem: A knight starts at square (0,0) on an infinite chessboard. What is the minimum number of knight moves needed to reach square (4,5)?
- Problem: The complete graph K6 has 15 edges. A perfect matching of 3 disjoint edges is removed. How many edges remain?