ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(-7 // 2, 7 // -2, -7 % 2, 7 % -2)
- A. -3 -3 -1 1
- B. -4 -3 1 -1
- C. -3 -4 -1 1
- D. -4 -4 1 -1
Correct answer: D. -4 -4 1 -1
Floor division rounds toward negative infinity, so -7 // 2 is -4 and 7 // -2 is -4. The remainder takes the sign of the divisor: -7 % 2 is 1 and 7 % -2 is -1.
More Python Programming questions
- What is printed? python def pairs(a, t): a = sorted(a) i, j, c = 0, len(a) - 1, 0 while i < j: s = a[i] + a[j] if s == t: c += 1 i += 1 j…
- What is printed? python def countk(a, k): pre = {0: 1} s = 0 ans = 0 for x in a: s += x ans += pre.get(s - k, 0) pre[s] = pre.get(s, 0) +…
- What is printed? python from collections import deque g = ['..#', '.##', '...'] def bfs(g): R, C = len(g), len(g[0]) d = {(0, 0): 0} q =…
- What is printed? python from functools import lrucache calls = 0 @lrucache(maxsize=None) def f(n): global calls calls += 1 if n < 2…
- What is printed? python def greedy(coins, amt): cnt = 0 for c in sorted(coins, reverse=True): cnt += amt // c amt %= c return cnt if amt…
- What is printed? python import bisect def lis(a): t = [] for x in a: i = bisect.bisectleft(t, x) if i == len(t): t.append(x) else: t[i] =…