ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(divmod(-(10 ** 20), 7))
- A. (-14285714285714285714, 2)
- B. (-14285714285714285714, 5)
- C. (-14285714285714285715, 2)
- D. (-14285714285714285715, 5)
Correct answer: D. (-14285714285714285715, 5)
Python's // floors toward negative infinity, and % takes the sign of the divisor. 10^20 = 7 * 14285714285714285714 + 2, so -(10^20) = 7 * (-14285714285714285715) + 5, giving remainder 5.
More Python Programming questions
- What is printed? python import heapq h = [4, 1, 3] heapq.heapify(h) print(h[0], sorted(h))
- What is printed? python from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=3) d.append(6) d.appendleft(0) print(list(d))
- What is printed? python x = [0] 3 y = [[0] 2] 2 y[0][1] = 7 print(x, y)
- What is printed? python import bisect vals = [10, 20, 30] print(bisect.bisectleft(vals, 0), bisect.bisectleft(vals, 35)…
- What is printed? python from collections import deque d = deque('abcde') d.rotate(2) print(''.join(d), ''.join(deque('abcde').reversed()))
- What is printed? python print(int('0' 5 + '7') + int(' -3 '), len(str(int('9' 50) + 1)))