0% found this document useful (0 votes)
2 views3 pages

Python Pattern Programs

The document provides a collection of common pattern programs in Python, including right-angled triangles, pyramids, inverted pyramids, diamonds, number triangles, and Floyd's triangle. Each pattern is demonstrated with code snippets and their corresponding outputs for a specified number of rows (n = 5). These examples illustrate how to use loops and string manipulation to create various visual patterns in the console.

Uploaded by

warzonevivo123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Pattern Programs

The document provides a collection of common pattern programs in Python, including right-angled triangles, pyramids, inverted pyramids, diamonds, number triangles, and Floyd's triangle. Each pattern is demonstrated with code snippets and their corresponding outputs for a specified number of rows (n = 5). These examples illustrate how to use loops and string manipulation to create various visual patterns in the console.

Uploaded by

warzonevivo123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Common Pattern Programs in Python

Right-angled triangle (increasing)


n = 5
for i in range(1, n + 1):
print("*" * i)
Output:
*
**
***
****
*****

Right-angled triangle (decreasing)


n = 5
for i in range(n, 0, -1):
print("*" * i)
Output:
*****
****
***
**
*

Pyramid pattern
n = 5
for i in range(1, n + 1):
print(" " * (n - i) + "*" * (2 * i - 1))
Output:
*
***
*****
*******
*********

Inverted pyramid pattern


n = 5
for i in range(n, 0, -1):
print(" " * (n - i) + "*" * (2 * i - 1))
Output:
*********
*******
*****
***
*

Diamond pattern
n = 5
for i in range(1, n + 1):
print(" " * (n - i) + "*" * (2 * i - 1))
for i in range(n - 1, 0, -1):
print(" " * (n - i) + "*" * (2 * i - 1))
Output:
*
***
*****
*******
*********
*******
*****
***
*

Number triangle
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="")
print()
Output:
1
12
123
1234
12345

Floyd's Triangle
n = 5
num = 1
for i in range(1, n + 1):
for j in range(i):
print(num, end=" ")
num += 1
print()
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

You might also like