ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
grid = ['a..', '.a.', '...']
cnt = sum(row.count('.') for row in grid)
diag = ''.join(grid[i][i] for i in range(3))
print(cnt, diag)
  1. A. 7 aa.
  2. B. 6 aa.
  3. C. 7 a.a
  4. D. 5 aa.

Correct answer: A. 7 aa.

The dots are 2 + 2 + 3 = 7. The diagonal cells are grid[0][0] = 'a', grid[1][1] = 'a' and grid[2][2] = '.'.

More Python Programming questions

Exams that ask this topic