ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(round(0.5 + 1), round(-0.5 - 1), round(2.5 - 0.0001))
- A. 2 -1 2
- B. 2 -2 3
- C. 2 -3 2
- D. 2 -2 2
Correct answer: D. 2 -2 2
round uses half to even on exact halves, so 1.5 goes to 2 and -1.5 goes to -2. 2.4999 is below the halfway point and rounds down to 2.
More Python Programming questions
- What is printed? python print(0.1 + 0.2 - 0.3, 0.3 - 0.1 - 0.2, 1 / 49 49, 1 / 10 10)
- What is printed? python import bisect a = [10, 9, 2, 5, 3, 7, 101, 18] tails = [] for x in a: i = bisect.bisectleft(tails, x) if i ==…
- What is printed? python from itertools import product print(list(product('ab', repeat=2)), list(product([0, 1], 'x')))
- What is printed? python d = {'pen': 3, 'cap': 5, 'ink': 3, 'box': 1} print(sorted(d.items(), key=lambda kv: (-kv[1], kv[0]))[:3])
- What is printed? python from collections import deque n = 4 edges = [(0, 2), (1, 2), (2, 3), (0, 3)] indeg = [0] n adj = [[] for in…
- What is printed? python def cnt(xs, T): xs = sorted(xs) lo, hi, total = 0, len(xs) - 1, 0 while lo < hi: if xs[lo] + xs[hi] <= T: total +=…