Display Multiplication Table in Python

Beginner
⏱️ 8 min read
📚 Updated: May 2026
🎯 2 Code Examples
Loops

What you’ll learn

  • How a times table maps to a simple loop in code.
  • How to print each row as base x i = product.
  • Two Python versions: fixed base and user input, plus live preview.

Overview

Pick a base number and multiply it by 1, 2, 3, ..., 10. A loop prints each row automatically.

Two programs

Fixed table for 5 and user-entered base.

Live preview

Try any integer base and print 1 to 10 rows.

Interview-ready

Simple loop pattern with clear output formatting.

Prerequisites

Python loops, print formatting, and basic input conversion.

  • Know for i in range(1, 11) and multiplication using *.
  • Optional: convert user input with int(input()) in interactive scripts.

The idea

Fix one base number n. For each counter value i from 1 to 10, print n * i as one row.

The formula is always the same; only i changes each step.

Live preview

Default base is 5 to match example 1. Change it and click Print table.

Prints rows from 1 to 10. Enter a whole number.

Live result
Press "Print table".

Algorithm

Goal: print base * i for i = 1..10.

Set base and limit

Choose a base number and how many rows to print (10 here).

Loop from 1 to limit

For each i, compute product = base * i.

Print formatted row

Output as base x i = product.

📜 Pseudocode

Pseudocode
procedure print_table(base, last):
    print heading
    for i from 1 to last:
        print base, i, and base * i
1

Table for 5 (fixed base)

Classic 5-times table from 1 to 10.

python
def print_multiplication_table(base: int, last: int) -> None:
    print(f"Multiplication table for {base}:")
    for i in range(1, last + 1):
        print(f"{base} x {i} = {base * i}")

def main() -> None:
    base = 5
    last = 10
    print_multiplication_table(base, last)

if __name__ == "__main__":
    main()
2

Table for a number you type

Reads a positive integer and prints its table up to 10.

python
def print_multiplication_table(base: int, last: int) -> None:
    print(f"Multiplication table for {base}:")
    for i in range(1, last + 1):
        print(f"{base} x {i} = {base * i}")

def main() -> None:
    try:
        n = int(input("Enter a positive integer: ").strip())
    except ValueError:
        print("Could not read an integer.")
        return

    if n <= 0:
        print("Please enter a positive integer.")
        return

    print_multiplication_table(n, 10)

if __name__ == "__main__":
    main()

Notes

Formatting. You can align outputs with fixed-width formatting if needed.

Range control. Let users choose last row (10, 12, 20) if assignment asks.

❓ FAQ

It is a list of products like n x 1, n x 2, and so on. Each row is one multiplication.
Because the same pattern repeats for each row. Only the counter changes.
School tables often use 1 to 10. You can change the upper limit to 12 or any positive number.
Yes. A while loop works too, but for is simpler when the number of rows is known.
Multiplication still works, but classic school tables usually use positive bases. You can validate input and reject non-positive values if needed.
If you print k rows, time is O(k) and extra space is O(1), ignoring output text.

🔄 Input / output

Example 1 uses fixed values. Example 2 reads one integer from user input and prints rows 1 through 10.

Edge cases

Input

Non-integer text

Catch conversion errors and show a clear message.

Base

Zero or negative base

Decide whether to allow or reject based on assignment rules.

⏱️ Time and space complexity

TaskTimeExtra space
Print last rowsO(last)O(1)

Summary

  • Core loop: print base * i for each row index.
  • Cost: linear in number of printed rows.
  • Extension: take both base and row limit from user input.
Did you know?

A multiplication table for a number n is the list n x 1, n x 2, .... A loop prints these rows automatically instead of writing each line by hand.

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.

8 people found this page helpful