Problem 147187 · easy · Phase 01 Prerequisites & Setup

Draw an X

nested loops · strings · conditionals

Draw a big letter X inside an n x n square. Return a list of n strings where a cell holds X if it lies on the main diagonal (row index equals column index) or on the anti-diagonal (row index plus column index equals n - 1), and . otherwise.

Examples

Input:  n = 3
Output: ["X.X", ".X.", "X.X"]

Input:  n = 4
Output: ["X..X", ".XX.", ".XX.", "X..X"]

Constraints

  • 0 <= n <= 40
  • Return [] when n is 0.

Goals

  • Recognise the two diagonals of a square by their indices
  • Fill a square grid cell by cell
Starting Python…