Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
104 views

Python Patterns Programs

Uploaded by

shahmeet644
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)
104 views

Python Patterns Programs

Uploaded by

shahmeet644
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/ 26

50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

50 Python Pattern Programs


Here are 50 different Python programs to print patterns. Each pattern includes a
description and the corresponding Python code. Learn and explore different patterns
with CodeWithCurious.

1. Right Angle Triangle Pattern

for i in range(1, 6):


print('*' * i)

*
* *
* * *
* * * *
* * * * *

2. Inverted Right Angle Triangle Pattern

for i in range(5, 0, -1):


print('*' * i)

*****
****
***
**
*

http://127.0.0.1:5500/index.html Page 1 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

3. Pyramid Pattern

for i in range(1, 6):


print(' ' * (5 - i) + '*' * (2 * i - 1))

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *

4. Inverted Pyramid Pattern

for i in range(5, 0, -1):


print(' ' * (5 - i) + '*' * (2 * i - 1))

*********
*******
*****
***
*

5. Diamond Pattern

for i in range(1, 6):

http://127.0.0.1:5500/index.html Page 2 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

print(' ' * (5 - i) + '*' * (2 * i - 1))


for i in range(4, 0, -1):
print(' ' * (5 - i) + '*' * (2 * i - 1))

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

6. Hollow Square Pattern

for i in range(5):
for j in range(5):
if i == 0 or i == 4 or j == 0 or j == 4:
print('*', end='')
else:
print(' ', end='')
print()

***** * * *
* * * *****

http://127.0.0.1:5500/index.html Page 3 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

7. Full Square Pattern

for i in range(5):
print('*' * 5)

***** *****
***** *****
*****

8. Right Angle Triangle (Number Pattern)

for i in range(1, 6):


print(' '.join(str(x) for x in range(1, i + 1)))

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

9. Inverted Right Angle Triangle (Number Pattern)

for i in range(5, 0, -1):


print(' '.join(str(x) for x in range(1, i + 1)))

http://127.0.0.1:5500/index.html Page 4 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

10. Floyd's Triangle

num = 1
for i in range(1, 6):
for j in range(1, i + 1):
print(num, end=' ')
num += 1
print()

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

11. Hollow Right Angle Triangle

for i in range(1, 6):


for j in range(1, i + 1):
if j == 1 or j == i or i == 5:
print('*', end='')
else:
print(' ', end='')
print()

http://127.0.0.1:5500/index.html Page 5 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

*
*
*
* *
*
*****
*

12. Hollow Pyramid Pattern

for i in range(1, 6):


for j in range(5 - i):
print(' ', end='')
for j in range(2 * i - 1):
if j == 0 or j == 2 * i - 2 or i == 5:
print('*', end='')
else:
print(' ', end='')
print()

*
* *
* *
* *
*********

13. Hollow Diamond Pattern

n = 5
for i in range(1, n + 1):

http://127.0.0.1:5500/index.html Page 6 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

print(' ' * (n - i) + '*' + ' ' * (2 * i - 3) + ('*' if i > 1 else ''))


for i in range(n - 1, 0, -1):
print(' ' * (n - i) + '*' + ' ' * (2 * i - 3) + ('*' if i > 1 else ''))

*
* *
* *
* *
*********
* *
* *
* *
*

14. Hollow Diamond (Number Pattern)

n = 5
for i in range(1, n + 1):
for j in range(1, n - i + 1):
print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print(i, end='')
else:
print(' ', end='')
print()

1
2 2
3 3
4 4
5 5
4 4
3 3
2 2

http://127.0.0.1:5500/index.html Page 7 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

15. Butterfly Pattern

for i in range(1, 6):


for j in range(1, i + 1):
print('*', end='')
for j in range(1, 2 * (5 - i)):
print(' ', end='')
for j in range(1, i + 1):
print('*', end='')
print()

* * ** ** ***
*** **** ****
********* ****
**** *** *** **
** * *

16. Hollow Number Pyramid

for i in range(1, 6):


for j in range(1, 6 - i):
print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print(i, end='')

http://127.0.0.1:5500/index.html Page 8 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

else:
print(' ', end='')
print()

1
2 2
3 3
4 4
5 5

17. Full Star Pyramid

for i in range(1, 6):


print(' ' * (5 - i) + '*' * (2 * i - 1))

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *

18. Inverted Full Star Pyramid

for i in range(5, 0, -1):


print(' ' * (5 - i) + '*' * (2 * i - 1))

*********
*******

http://127.0.0.1:5500/index.html Page 9 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

*****
***
*

19. Left Aligned Pyramid Pattern

for i in range(1, 6):


print('*' * i)

*
* *
* * *
* * * *
* * * * *

20. Right Aligned Pyramid Pattern

for i in range(1, 6):


print(' ' * (5 - i) + '*' * i)

* * *
* * *
* * * *
* * * * *

http://127.0.0.1:5500/index.html Page 10 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

21. Pascal's Triangle

n = 5
for i in range(n):
for j in range(n - i - 1):
print(' ', end='')
for j in range(i + 1):
print(str(math.comb(i, j)) + ' ', end='')
print()

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

22. Zig-Zag Pattern

for i in range(1, 6):


if i % 2 == 0:
print(' ' * (i - 1) + '*')
else:
print('*' * i)

*
*
*
*
*

http://127.0.0.1:5500/index.html Page 11 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

23. Hourglass Pattern

for i in range(5, 0, -1):


print(' ' * (5 - i) + '*' * (2 * i - 1))
for i in range(2, 6):
print(' ' * (5 - i) + '*' * (2 * i - 1))

*********
*******
*****
***
*
***
*****
*******
*********

24. Diamond Shape with Numbers

for i in range(1, 6):


print(' ' * (5 - i) + str(i) * (2 * i - 1))
for i in range(4, 0, -1):
print(' ' * (5 - i) + str(i) * (2 * i - 1))

1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4
3 3 3 3 3
2 2 2
1

http://127.0.0.1:5500/index.html Page 12 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

25. Hollow Rhombus Pattern

for i in range(1, 6):


for j in range(1, 6):
if i == 1 or i == 5 or j == 1 or j == 5:
print('*', end='')
else:
print(' ', end='')
print()

***** * * *
* * * *****

26. Numeric Pyramid

for i in range(1, 6):


print(' ' * (5 - i) + ' '.join(str(x) for x in range(1, i + 1)))

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

http://127.0.0.1:5500/index.html Page 13 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

27. Hollow Diamond with Numbers

for i in range(1, 6):


for j in range(1, 6 - i):
print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print(i, end='')
else:
print(' ', end='')
print()
for i in range(4, 0, -1):
for j in range(1, 6 - i):
print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print(i, end='')
else:
print(' ', end='')
print()

1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1

28. Reverse Pyramid with Numbers

for i in range(5, 0, -1):


print(' ' * (5 - i) + ' '.join(str(x) for x in range(1, i + 1)))

http://127.0.0.1:5500/index.html Page 14 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

29. Diamond Star Pattern

for i in range(1, 6):


print(' ' * (5 - i) + '*' * (2 * i - 1))
for i in range(4, 0, -1):
print(' ' * (5 - i) + '*' * (2 * i - 1))

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

30. Full Number Pyramid

for i in range(1, 6):


print(' ' * (5 - i) + ''.join(str(x) for x in range(1, i + 1)))

http://127.0.0.1:5500/index.html Page 15 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 1 2
1 2 3
1 2 3 4
1 2 3 4 5

31. Checkerboard Pattern

for i in range(5):
for j in range(5):
if (i + j) % 2 == 0:
print('*', end='')
else:
print(' ', end='')
print()

* * *
* *
* * *
* *
* * *

32. Hollow Circle Pattern

import math
for i in range(1, 6):
for j in range(1, 6):
if math.dist([i, j], [3, 3]) <= 2:
print('*', end='')
else:

http://127.0.0.1:5500/index.html Page 16 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

print(' ', end='')


print()

*****
* *
* *
* *
*****

33. Triangle of Numbers

for i in range(1, 6):


for j in range(1, i + 1):
print(j, end='')
print()

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

34. Rhombus of Numbers

for i in range(1, 6):


print(' ' * (5 - i) + ''.join(str(x) for x in range(1, i + 1)))
for i in range(4, 0, -1):
print(' ' * (5 - i) + ''.join(str(x) for x in range(1, i + 1)))

http://127.0.0.1:5500/index.html Page 17 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2 1

35. Number Pattern (Decreasing)

for i in range(5, 0, -1):


print(' '.join(str(x) for x in range(1, i + 1)))

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

36. Hollow Inverted Pyramid

for i in range(5, 0, -1):


for j in range(1, 2 * i - 1):
if j == 1 or j == 2 * i - 2 or i == 5:
print('*', end='')
else:
print(' ', end='')
print()

http://127.0.0.1:5500/index.html Page 18 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

*********
* *
* *
* *
*

37. Cross Pattern

for i in range(5):
for j in range(5):
if i == j or i + j == 4:
print('*', end='')
else:
print(' ', end='')
print()

* *
* *
*
* *
* *

38. Number Inverted Pyramid

for i in range(5, 0, -1):


print(' '.join(str(x) for x in range(1, i + 1)))

http://127.0.0.1:5500/index.html Page 19 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

39. Right Angle Star Triangle

for i in range(1, 6):


print(' ' * (5 - i) + '*' * i)

* * *
* * *
* * * *
* * * * *

40. Left Angle Number Triangle

for i in range(1, 6):


print(' '.join(str(x) for x in range(1, i + 1)))

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

http://127.0.0.1:5500/index.html Page 20 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

41. Star Hollow Triangle

for i in range(1, 6):


for j in range(1, 6):
if j == 1 or j == i or i == 5:
print('*', end='')
else:
print(' ', end='')
print()

*
* *
* *
* *
*****

42. Upside Down Right Triangle

for i in range(5, 0, -1):


print(' ' * (5 - i) + '*' * i)

***** ****
*** ** *

http://127.0.0.1:5500/index.html Page 21 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

43. Parallelogram Star Pattern

for i in range(5):
print(' ' * i + '*' * 5)

*****
*****
*****
*****
*****

44. Inverted Parallelogram Pattern

for i in range(5):
print(' ' * (5 - i) + '*' * 5)

*****
*****
*****
*****
*****

45. Reverse Hollow Diamond

for i in range(5, 0, -1):


print(' ' * (5 - i) + '*' + ' ' * (2 * i - 3) + ('*' if i > 1 else ''))
for i in range(4, 0, -1):
print(' ' * (5 - i) + '*' + ' ' * (2 * i - 3) + ('*' if i > 1 else ''))

http://127.0.0.1:5500/index.html Page 22 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

*****
* *
* *
*
*
* *
* *
*****

46. Inverted Hollow Pyramid with Stars

for i in range(5, 0, -1):


for j in range(1, 2 * i - 1):
if j == 1 or j == 2 * i - 2 or i == 5:
print('*', end='')
else:
print(' ', end='')
print()

*********
* *
* *
* *
*

47. Full Hollow Diamond

for i in range(1, 6):

http://127.0.0.1:5500/index.html Page 23 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

for j in range(1, 6 - i):


print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print('*', end='')
else:
print(' ', end='')
print()
for i in range(4, 0, -1):
for j in range(1, 6 - i):
print(' ', end='')
for j in range(1, 2 * i):
if j == 1 or j == 2 * i - 1:
print('*', end='')
else:
print(' ', end='')
print()

1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1

48. Rectangle of Numbers

for i in range(5):
for j in range(1, 6):
print(j, end=' ')
print()

1 2 3 4 5

http://127.0.0.1:5500/index.html Page 24 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

1 2 3 4 5 1 2 3 4
5 1 2 3 4 5 1 2 3
4 5

49. Reverse Star Pattern

for i in range(5, 0, -1):


print('*' * i)

*****
****
***
**
*

50. Pyramid of Numbers

for i in range(1, 6):


print(' ' * (5 - i) + ''.join(str(x) for x in range(1, i + 1)))

1 1 2
1 2 3
1 2 3 4
1 2 3 4 5

http://127.0.0.1:5500/index.html Page 25 of 26

Curious_.Programmer | CodeWithCurious.com
50 Python Pattern Programs - CodeWithCurious 13/01/25, 10:00

Download Completed PDF


Uploaded on Telegram
Channel

Link in BIO

© 2025 CodeWithCurious.com - All Rights Reserved

http://127.0.0.1:5500/index.html Page 26 of 26

Curious_.Programmer | CodeWithCurious.com

You might also like