Multiplication Triangle in Python

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:
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 100Complete Python Program
The outer loop selects the row number i. The inner loop prints products from i*1 to i*i.
rows = 10
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(i * j, end=" ")
print()🧠 How It Works
Set the number of rows
rows = 10 controls how many lines are printed.
Outer loop chooses the row
for i in range(1, rows + 1) sets the current row number.
Inner loop prints i products
for j in range(1, i + 1) runs exactly i times, printing i*j.
New line after each row
print() moves to the next row after finishing the inner loop.
Multiplication triangle
Total values printed are 1+2+…+n = n(n+1)/2, so runtime is O(n²).
Variation — User Input + Neat Alignment
Let the user choose rows and print a neatly aligned triangle using fixed-width formatting.
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
Row i prints products i*1 through i*i.
The inner loop runs i times, which forms the triangle.
Total printed values follow n(n+1)/2.
Use formatting to keep columns aligned for larger outputs.
❓ Frequently Asked Questions
j ≤ i.{i*j:4d} or compute a width based on rows*rows.Explore More Python Number Patterns!
Once you’re comfortable with multiplication patterns, try factorial and Fibonacci-based patterns too.
Multiplication patterns are a fun way to visualize arithmetic. The diagonal of this triangle shows squares: 1, 4, 9, 16, ...
7 people found this page helpful
