Python Multiplication Table Program

Beginner
5 min read
Updated: Oct 2026
2 programs
Live preview

What Is a Multiplication Table?

A multiplication table for a number n lists products n × 1, n × 2, n × 3, … up to a chosen limit (commonly 10).

Remember
For n = 5 (limit 10):
  5 × 1 = 5
  5 × 2 = 10
  5 × 3 = 15
  …
  5 × 10 = 50

Pattern:
  for i from 1 to limit:
      print n × i = (n * i)
nin × i
515
5210
51050

How to Print a Multiplication Table in Python

Four clear steps — a simple for loop does the work.

  1. Choose the number n (hard-coded or from input).
  2. Choose the upper limit (often 10).
  3. Loop i from 1 to that limit.
  4. Print each row as n × i = n * i.
MethodIdeaTimeBest for
Fixed 1–10for i in range(1, 11)O(1) rowsClassic beginner demos
Custom limitLoop to a parameter limitO(limit)Flexible / interview follow-ups

Pseudocode

Pseudocode
function PrintTable(n, limit):
    for i from 1 to limit:
        print n, "×", i, "=", n * i

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
Row formulan * i for i = 1..limit
Default limit10 in many textbooks
Loopfor i in range(1, limit + 1)
Outputprint(f"{n} × {i} = {n * i}")
Inputint(input()) when asked
Classic check5 × 10 = 50

Live Preview

Enter a number to print its table from 1 to 10.

Whole numbers from −99 to 99. Rows 1 through 10.

Result
5 × 1 = 5
5 × 2 = 10
5 × 3 = 15
5 × 4 = 20
5 × 5 = 25
5 × 6 = 30
5 × 7 = 35
5 × 8 = 40
5 × 9 = 45
5 × 10 = 50

Worked Walkthrough — n = 5, limit 5

Each loop step multiplies n by the current i.

Calculation
i = 1 → 5 × 1 = 5
i = 2 → 5 × 2 = 10
i = 3 → 5 × 3 = 15
i = 4 → 5 × 4 = 20
i = 5 → 5 × 5 = 25

Stop when i exceeds the limit

Python Programs

Start with the classic 1–10 table. Then use a custom limit when the problem asks for more (or fewer) rows.

Example 1 — Fixed 1–10 Table

Print n × 1 through n × 10 with a simple for loop.

python
n = 5

for i in range(1, 11):
    print(f"{n} × {i} = {n * i}")

How It Works

  1. Set n = 5 (or read it with int(input()) later).
  2. range(1, 11) yields 1 through 10.
  3. Each iteration prints one row using n * i.
  4. An f-string builds the readable n × i = product line.
  5. After i = 10, the loop stops — ten rows printed.

Example 2 — Custom Limit

Accept n and a row count so the table length is flexible.

python
def print_table(n, limit):
    if limit < 1:
        raise ValueError("Limit must be at least 1.")

    for i in range(1, limit + 1):
        print(f"{n} × {i} = {n * i}")


print_table(7, 5)

How It Works

  1. Pass both the number n and the upper limit.
  2. Reject limit < 1 so the loop has a sensible range.
  3. range(1, limit + 1) prints 1..limit rows.
  4. For print_table(7, 5) you get five lines ending at 7 × 5 = 35.
  5. Change the limit without rewriting the loop body.

Edge Cases & Pitfalls

Check these before calling the solution done.

Limit ≤ 0

No rows

Validate the upper bound before looping.

n = 0

All zeros

Every product is 0 — still a valid table.

Off-by-one

Use limit + 1

range(1, 10) stops at 9 and misses the last row.

Input

Convert carefully

Wrap int(input()) in try/except if reading from the console.

Time and Space Complexity

ProgramTimeExtra space
Fixed 1–10O(1) (10 rows)O(1)
Custom limitO(limit)O(1)

Work grows with the number of rows printed. No extra lists are required.

Key Takeaways

  • Pattern: loop i and print n * i.
  • Default: many problems use limit 10.
  • Flexible: pass a custom limit when needed.
  • Test: 5 × 10 = 50 is the last row of the classic table.

One line: for each i from 1 to limit, print n × i = n * i.

Frequently Asked Questions

For a number n, it is the list of products n×1, n×2, n×3, … up to a chosen limit (often 10).
A loop prints every row automatically. Writing each line by hand does not scale when the limit changes.
Beginner programs often print 1 through 10. Interviews may ask for a custom upper limit.
Yes mathematically. Products still work (for example 0×5 = 0, (−3)×4 = −12). Validate only if your problem requires positive n.
Printing k rows takes O(k) time and O(1) extra space.

Next: Natural Number

Check whether an integer is a natural number.

Natural number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful