📘 Lesson  ·  Lesson 77

Pattern Printing Programs

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.

Pattern Printing Programs in Python

Pattern programs nested loops से stars या numbers की आकृतियाँ print करते हैं — practice और 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

कैसे काम करता है

  • बाहरी loop rows control करता है; भीतरी loop हर row के items।
  • Stars से पहले spaces alignment बनाते हैं (pyramids)।

सारांश

  • Pattern programs nested loops से stars या numbers की आकृतियाँ print करते हैं — practice और exams का पसंदीदा।
← Back to Python Tutorial
🔗

Share this topic with a friend

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

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

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

\n