Home Python Interview Programs Multiplication Table Python Multiplication Table Program Definition
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).
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) Approach
How to Print a Multiplication Table in Python Four clear steps — a simple for loop does the work.
Choose the number n (hard-coded or from input). Choose the upper limit (often 10). Loop i from 1 to that limit. Print each row as n × i = n * i. Method Idea Time Best for Fixed 1–10 for i in range(1, 11)O(1) rowsClassic beginner demos Custom limit Loop to a parameter limit O(limit)Flexible / interview follow-ups
Pseudocode function PrintTable(n, limit):
for i from 1 to limit:
print n, "×", i, "=", n * i Reference
Cheat Sheet Keep these facts handy while writing the program.
Topic Detail Row formula n * i for i = 1..limitDefault limit 10 in many textbooksLoop for i in range(1, limit + 1)Output print(f"{n} × {i} = {n * i}")Input int(input()) when askedClassic check 5 × 10 = 50
Try it
Live Preview Enter a number to print its table from 1 to 10.
Trace
Worked Walkthrough — n = 5, limit 5 Each loop step multiplies n by the current i.
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 Code
Python Programs Start with the classic 1–10 table. Then use a custom limit when the problem asks for more (or fewer) rows.
1. Fixed 1–10 2. Custom limit Example 1 — Fixed 1–10 Table Print n × 1 through n × 10 with a simple for loop.
n = 5
for i in range(1, 11):
print(f"{n} × {i} = {n * i}") 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 How It Works Set n = 5 (or read it with int(input()) later). range(1, 11) yields 1 through 10.Each iteration prints one row using n * i. An f-string builds the readable n × i = product line. 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.
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) 7 × 1 = 7
7 × 2 = 14
7 × 3 = 21
7 × 4 = 28
7 × 5 = 35 How It Works Pass both the number n and the upper limit. Reject limit < 1 so the loop has a sensible range. range(1, limit + 1) prints 1..limit rows.For print_table(7, 5) you get five lines ending at 7 × 5 = 35. 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.
Analysis
Time and Space Complexity Program Time Extra space Fixed 1–10 O(1) (10 rows)O(1)Custom limit O(limit)O(1)
Work grows with the number of rows printed. No extra lists are required.
Remember
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 What is a multiplication table? For a number n, it is the list of products n×1, n×2, n×3, … up to a chosen limit (often 10).
Why use a loop? A loop prints every row automatically. Writing each line by hand does not scale when the limit changes.
What is the usual range? Beginner programs often print 1 through 10. Interviews may ask for a custom upper limit.
Can n be zero or negative? Yes mathematically. Products still work (for example 0×5 = 0, (−3)×4 = −12). Validate only if your problem requires positive n.
What is the time complexity? Printing k rows takes O(k) time and O(1) extra space.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion