Print a Multiplication Table

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.9
Write a function multiplication_table(n) that returns a list of strings, one per line, representing the multiplication table of n from 1 to 10. Each line must have the exact format "n x i = result", e.g. "3 x 1 = 3".

Examples

Example 1
Input
multiplication_table(2)[0:3]
Output
["2 x 1 = 2", "2 x 2 = 4", "2 x 3 = 6"]
Explanation

First three lines of the table for 2.

Constraints

  • n is a positive integer.
  • Result has exactly 10 lines, for i = 1 through 10.

Topics

Loopsfor looppattern printing

Companies

CognizantCapgemini

Hints

Hint 1

Loop `for i in range(1, 11):` and format each line with an f-string.

Hint 2

Append each formatted line to a results list.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.