📘 Lesson  ·  Lesson 77

Pattern Printing Programs

Pattern Printing Programs in Python

Pattern programs use nested loops to print shapes with stars or numbers — a favourite for practice and exams.

Python Program

Python
# Right triangle of stars
for i in range(1, 6):
    print("* " * i)

print()

# Number pyramid
n = 4
for i in range(1, n + 1):
    print(" " * (n - i) + "* " * i)

print()

# Number triangle
for i in range(1, 5):
    for j in range(1, i + 1):
        print(j, end=" ")
    print()

Expected Output

* * * * * * * * * * * * * * * * * * * * * * * * * 1 1 2 1 2 3 1 2 3 4

How it Works

  • The outer loop controls rows; the inner loop controls items per row.
  • Spaces before stars create alignment (pyramids).

Summary

  • Pattern programs use nested loops to print shapes with stars or numbers — a favourite for practice and exams.
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.