Python Multiplication Number Triangle Pattern

Beginner
5 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A triangular multiplication pattern prints the products i×1, i×2, … up to i×i on each row.

Remember
Rule: on row i, print i*j for j = 1..i

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25   ← rows = 5

Follows the powers of 11 in Program 48; next is the rotating number pattern in Program 50.

How to Solve It

One nested loop: outer picks the row base i, inner prints the first i multiples.

MethodIdeaBest for
Space-separatedPrint i * j for j = 1..iLearning, interviews, exams
Fixed widthSame products with f"{i * j:3d}"Neater columns

Pseudocode

Pseudocode
for i from 1 to rows:
    for j from 1 to i:
        print i * j and a space
    print newline

Cheat sheet

GoalPattern
Walk rowsfor i in range(1, rows + 1):
Walk columnsfor j in range(1, i + 1):
Print productprint(i * j, end=" ")
Align columnsprint(f"{i * j:3d}", end="")
End the rowprint()

Printing Numbers vs Starting a New Line

APIEffectUse for
print(i * j, end=" ")Stays on the same lineEach product plus a trailing space
print()Ends the current lineAfter the column loop finishes a row

Print products without a newline, then end the row once.

Live Preview

Change the row count and the multiplication triangle updates instantly.

Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 products
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 

Worked Walkthrough — rows = 4

Trace each row’s products from i*1 through i*i.

iProducts i*jPrinted row
111
22, 42 4
33, 6, 93 6 9
44, 8, 12, 164 8 12 16

Total products for n rows = n(n+1)/2. Last value on row i is always i*i.

Python Programs

Three complete programs: fixed 5 rows, input() rows, and fixed-width columns. Use View Output for sample results.

Example 1 — Fixed rows = 5

Nested loops print i * j with a trailing space.

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

How It Works

1. Outer loop. i is the row multiplier — row 3 uses 3 as the base.

2. Inner loop. j runs from 1 to i; each cell prints i * j.

3. Newline. Bare print() after the inner loop starts the next row.

Example 2 — User Input Rows

Read the row count with input() and build the same triangle.

Python
try:
    rows = int(input("Enter number of rows: "))
except ValueError:
    print("Please enter a positive whole number.")
    raise SystemExit(1)

if rows < 1:
    print("Please enter a positive whole number.")
    raise SystemExit(1)

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

How It Works

1. Validate rows. Catch ValueError; require rows >= 1.

2. Same triangle. Only the bound changes from the literal 5 to the user value.

3. Safer input tip. Cap demos for readable output:

Safer input tip
if rows < 1 or rows > 10:
    print("Enter a whole number from 1 to 10.")
    raise SystemExit(1)

Example 3 — Fixed-Width Columns

Use :3d so single- and double-digit products stay aligned.

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

How It Works

1. Same products. Still i * j for j = 1..i.

2. Width 3. f"{i * j:3d}" reserves three columns per number so digits line up.

Edge Cases & Pitfalls

Check these before calling the solution done.

j <= rows

Inner loop always to rows

That prints a full rectangle (multiplication table). Keep j <= i for the triangle.

j * i

Print j * i instead of i * j

Same products — fine. Just stay consistent; both equal i * j.

print() inside

print() inside the inner loop

That puts every product on its own line. Call bare print() only after the column loop.

rows = 1

Single row

Output is just 1 — one product on one line.

no end

Forgot end=" "

Default print(i * j) puts each product on its own line. Use end=" " (or fixed width) inside the row.

input()

Catch ValueError

Bare int(input()) crashes on non-numeric text — wrap it in try/except ValueError.

Time and Space Complexity

ProgramTimeExtra space
Fixed / aligned (Examples 1, 3)O(n²)O(1)
User input (Example 2)O(n²)O(1)

Total printed products are 1 + 2 + … + n = n(n+1)/2, so work is quadratic in the row count.

Key Takeaways

  • Rule: on row i, print i*j for j = 1..i; last value is i*i.
  • Shape: triangular — row length grows with i; total prints = n(n+1)/2.
  • end=" " vs print(): products stay on the line; bare print() advances after each row.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each row i, print the first i multiples of i.

Frequently Asked Questions

A triangle where row i contains i values: i*1, i*2, … up to i*i. Row 4 prints 4 8 12 16.
Outer loop sets row i. Inner loop runs j = 1..i and prints i*j for each column.
The last value on row i is i*i. For i = 5, that is 25.
Yes — change the loop limit or read rows from user input with int(input()) — see Example 2.
Change the inner loop to j = 1..rows on every row: for j in range(1, rows + 1).
O(n²) for n rows because total prints are 1+2+…+n = n(n+1)/2.
Program 48 is a 1D powers-of-11 sequence with one loop. Program 49 uses nested loops for a multiplication triangle.
Use fixed-width formatting like print(f"{i * j:3d}", end="") so columns line up — see Example 3.
Use try/except ValueError around int(input()) and require rows >= 1 — see Example 2.

Did you know?

On row i, print i products: i*1, i*2, … up to i*i. Total prints = n(n+1)/2 — a triangular number, so time is O(n²).

Next: Rotating Number Pattern

Print rows that shift or rotate their digit sequences across lines.

Program 50 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