easy +10 pts

Generate a Multiplication Table

Create a 2D multiplication table using nested lists.

Write a function `multiplication_table(n: int) -> list` that takes an integer `n` (where `n >= 0`) and returns an `n x n` table (list of lists) where the element at row `i` and column `j` (0-indexed) is equal to `(i + 1) * (j + 1)`. For `n == 0`, return an empty list. The result should be a list of rows, each row being a list of integers.

Constraints

0 <= n <= 20. The function should be O(n^2) time.

Example

>>> multiplication_table(3)
[[1, 2, 3], [2, 4, 6], [3, 6, 9]]
>>> multiplication_table(0)
[]
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use a list comprehension to build each row.
Remember that rows and columns start at 1, not 0.
You can build the entire table with a nested list comprehension.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.