ProgrammingVery hardInfosys HackWithInfy · TCS CodeVita
What does the following Python 3 code print? print(round(2.5), round(3.5), round(2.675, 2))
- A. 2 4 2.68
- B. 3 4 2.68
- C. 3 4 2.67
- D. 2 4 2.67
Correct answer: D. 2 4 2.67
Python's round() uses banker's rounding to the nearest even digit for exact halfway floats (2.5->2, 3.5->4); 2.675 isn't exactly representable in binary floating point and rounds to 2.67, not 2.68.
More Python Programming questions
- What does the following Python 3 code print? print(0.1 + 0.2 == 0.3)
- What does the following Python 3 code print? print(bool([]), bool({}), bool(()), bool(0.0), bool("0"))
- What does the following Python 3 code print? print([] == False, [] is False)
- What does the following Python 3 code print? x = [1, 2, 3] y = [1, 2, 3] print(x == y, x is y)
- What does the following Python 3 code print? print(2 10, 2 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)
- What does the following Python 3 code print? print(id([1, 2]) == id([1, 2]))