Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Build Multiplication Table

Generate a rows x cols multiplication table (1-based indices) as a list of lists.

Python practice17 minLoops & IterationIntermediateLast updated March 15, 2026

Problem statement

Write build_multiplication_table(rows, cols) that returns a list of rows lists, each containing cols integers. The value at row i and column j should be (i+1) * (j+1), using 1-based multiplication factors. If rows or cols are zero, return an empty list.

Task

Practice nested loops and building 2D lists row by row.

Examples

3x3 table

Input

build_multiplication_table(3, 3)

Output

[[1, 2, 3], [2, 4, 6], [3, 6, 9]]

Rows and columns are 1-based. Row 2 column 3 = 2 * 3 = 6.

Input format

Two integers: rows and cols (each >= 0).

Output format

A list of lists representing the multiplication table.

Constraints

rows and cols are non-negative integers. Aim for O(rows * cols) time and space.

Samples

Sample 1

Input

build_multiplication_table(1, 4)

Output

[[1, 2, 3, 4]]

Single row with columns 1..4.