Problem 172482 · easy · Phase 01 Prerequisites & Setup

Aligned Multiplication Table

nested loops · strings · formatting

Return the n x n multiplication table as a list of n strings. Row r (1-based) holds the products r*1, r*2, ..., r*n. Every product is right-aligned to the width of the largest product in the table (n*n), and neighbouring cells are separated by a single space.

Examples

Input:  n = 3
Output: ["1 2 3", "2 4 6", "3 6 9"]

Input:  n = 4
Output: [" 1  2  3  4", " 2  4  6  8", " 3  6  9 12", " 4  8 12 16"]

Constraints

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

Goals

  • Generate every product in an n x n table with nested loops
  • Right-align numbers to a common width so columns line up
Starting Python…