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)
  1. A. [1, 4, 6, 4, 1] 1024
  2. B. [1, 4, 6, 4] 24
  3. C. [1, 4, 6, 4, 1] 24
  4. 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

Exams that ask this topic