Multiplication Triangle in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

How to print a multiplication triangle in Python. Row i prints i*1, i*2, ... up to i*i, creating a growing triangular shape.

This is a quick way to practice nested loops and understand how the inner loop length changes with each row.

⭐ Pattern Output

For rows = 10, the pattern looks like this:

Output
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100
1

Complete Python Program

The outer loop selects the row number i. The inner loop prints products from i*1 to i*i.

Python
rows = 10

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(i * j, end=" ")
    print()

🧠 How It Works

1

Set the number of rows

rows = 10 controls how many lines are printed.

Setup
2

Outer loop chooses the row

for i in range(1, rows + 1) sets the current row number.

Row control
3

Inner loop prints i products

for j in range(1, i + 1) runs exactly i times, printing i*j.

Value printing
4

New line after each row

print() moves to the next row after finishing the inner loop.

Line break
=

Multiplication triangle

Total values printed are 1+2+…+n = n(n+1)/2, so runtime is O(n²).

2

Variation — User Input + Neat Alignment

Let the user choose rows and print a neatly aligned triangle using fixed-width formatting.

Python
rows = int(input("Enter number of rows: "))
if rows < 1:
    raise ValueError("rows must be at least 1")

for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(f"{i*j:4d}", end=" ")
    print()

💡 Tips for Enhancement

Try These

  • Print a full multiplication table by running the inner loop to a fixed limit
  • Right-align rows by printing leading spaces based on row width
  • Use formatting to align columns for larger products
  • Replace multiplication with addition to print a sum triangle
  • Colorize output in the terminal (advanced) to highlight diagonals

Avoid

  • Forgetting print() after each row (all values will appear on one line)
  • Skipping input validation for rows
  • Using inconsistent spacing (output will look jagged)
  • Printing huge tables without considering readability

Key Takeaways

1

Row i prints products i*1 through i*i.

2

The inner loop runs i times, which forms the triangle.

3

Total printed values follow n(n+1)/2.

4

Use formatting to keep columns aligned for larger outputs.

❓ Frequently Asked Questions

A multiplication table prints a full rectangle (like 10×10). This prints only the triangular part where j ≤ i.
You can, but the first row would be all zeros. Usually patterns start at 1 to keep the output meaningful.
Use fixed-width formatting like {i*j:4d} or compute a width based on rows*rows.
O(n²), since total printed values are 1+2+…+n.

Explore More Python Number Patterns!

Once you’re comfortable with multiplication patterns, try factorial and Fibonacci-based patterns too.

All Number Patterns →
Did you know?

Multiplication patterns are a fun way to visualize arithmetic. The diagonal of this triangle shows squares: 1, 4, 9, 16, ...

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.

7 people found this page helpful