ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(divmod(-9, 4), divmod(9, -4), -9 % 4, 9 % -4)
- A. (-2, 3) (-3, -3) 3 -3
- B. (-3, 3) (-2, -3) 3 -3
- C. (-3, 3) (-3, -3) 3 -3
- D. (-3, -3) (-3, 3) -3 4
Correct answer: C. (-3, 3) (-3, -3) 3 -3
Floor division of -9 by 4 gives -3 with remainder 3, and 9 divided by -4 gives -3 with remainder -3. The % operator follows the same sign rules as divmod.
More Python Programming questions
- What is printed? python class C: k = 10 try: a = [k + x for x in range(3)] except NameError: a = 'NameError' print(C.a)
- What is printed? python a = [1, 2, 3, 4] a[1:3] = [9] print(a) b = [1, 2, 3, 4] try: b[::2] = [0] except ValueError: print('ValueError')
- What is printed? python from collections import Counter def ways(a, t): dp = Counter({0: 1}) for x in a: nd = Counter(dp) for s, c in…
- What is printed? python print(bin(5 ^ 3), int('101', 2) << 2, ~5, -~5)
- What is printed? python import math print(math.prod([]), math.prod([2, 3.0]))
- What is printed? python import heapq h = [1, 3] heapq.heapify(h) print(heapq.heapreplace(h, 0), sorted(h), heapq.heappushpop(h, 0)…