Build a Multiplication Table
Medium
Write a function multiplication_table(n) that returns an n x n multiplication table as a list of lists, where element [i][j] = (i+1)*(j+1), using a nested list comprehension.
Input
An integer n (table size).
Output
A list of n lists, each containing n integers.
Example
Input
multiplication_table(3)
Output
[[1, 2, 3], [2, 4, 6], [3, 6, 9]]
Use [[ (i+1)*(j+1) for j in range(n) ] for i in range(n) ].
15 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.