ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
def row(n):
r = [1]
for _ in range(n):
r = [1] + [r[i] + r[i + 1] for i in range(len(r) - 1)] + [1]
return r
print(row(4), sum(row(10)) % 1000)- A. [1, 4, 6, 4, 1] 1024
- B. [1, 4, 6, 4] 24
- C. [1, 4, 6, 4, 1] 24
- D. [1, 3, 3, 1] 24
Correct answer: C. [1, 4, 6, 4, 1] 24
Each new row is built from adjacent pairs of the previous row, which gives row 4 as 1, 4, 6, 4, 1. Row 10 sums to 1024, and 1024 mod 1000 is 24.
More Python Programming questions
- What is printed? python def pairs(a, t): a = sorted(a) l, r = 0, len(a) - 1 out = [] while l < r: s = a[l] + a[r] if s == t…
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def rev(h): prev = None while h: h.nxt, prev, h =…
- What is printed? python def cntpal(s): n = len(s) c = 0 for ctr in range(2 n - 1): l, r = ctr // 2, ctr // 2 + ctr % 2 while l >= 0 and r…
- What is printed? python import bisect a = [9, 7, 5, 3, 1] print(bisect.bisectleft(a, -6, key=lambda v: -v), bisect.bisectleft(a, 6…
- What is printed? python from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=5) d.rotate(2) d.appendleft(0) print(list(d)…
- What is printed? python print(max(['bb', 'aa', 'c'], key=len), min(['bb', 'aa', 'c'], key=len))