ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))
- A. 0 1 2 -1 2
- B. 0 0 2 -2 3
- C. 0 0 3 -2 2
- D. 0 0 2 -2 2
Correct answer: D. 0 0 2 -2 2
round uses half-to-even for exact halves. -0.5 and 0.5 both go to 0, 1.5 goes to 2, -1.5 goes to -2, and 2.5 goes to 2.
More Python Programming questions
- What is printed? python x = [3, 1, 2] print(sorted(x, reverse=True)[:2], x[::-1][1:], list(reversed(sorted(x))))
- What is printed? python print('%08.2f' % -1.5, '%+08d' % 42, '%-+5d|' % 7, '%x' % -255)
- What is printed? python print(2 10 == 1024, 2 10 == 1 << 10, 10 2 3, (10 2) 3)
- What is printed? python from itertools import accumulate print(list(accumulate([1, 2, 3], lambda a, b: a b)), list(accumulate('ab'…
- What is printed? python print(sorted({'b': 1, 'a': 1}.items()), list({3: 'x', 1: 'y'}), dict(zip('ab', [1, 2])), dict.fromkeys('ab', 0))
- What is printed? python print(len({1, 1.0, True, '1'}), len({'1', 1}), {1, 2} == {2.0, 1.0}, {0} == {False})