⚡ TL;DR
10 intermediate and advanced pattern programs in Python — spiral matrix, hollow star, diamond, Fibonacci, binary, wave, and more. Code with output.
A follow-up to our earlier Python pattern collection, this post covers 10 more intermediate and advanced patterns that are commonly asked in interviews. Each includes working code and expected output.
1. Spiral Matrix Pattern
Fill an n x n matrix with numbers in spiral order.
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7def spiral_matrix(n):
matrix = [[0] * n for _ in range(n)]
num, top, bottom, left, right = 1, 0, n - 1, 0, n - 1
while top <= bottom and left <= right:
for i in range(left, right + 1):
matrix[top][i] = num; num += 1
top += 1
for i in range(top, bottom + 1):
matrix[i][right] = num; num += 1
right -= 1
for i in range(right, left - 1, -1):
matrix[bottom][i] = num; num += 1
bottom -= 1
for i in range(bottom, top - 1, -1):
matrix[i][left] = num; num += 1
left += 1
for row in matrix:
print(" ".join(f"{v:2}" for v in row))
spiral_matrix(4)Output
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 72. Hollow Star Diamond
Print a diamond with only boundary stars.
*
* *
* *
* *
*def hollow_diamond(n):
for i in range(1, n + 1):
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 ""))
hollow_diamond(3)Output
*
* *
* *
* *
*3. Full Diamond Star Pattern
Classic diamond using stars.
*
***
*****
*******
*********
*******
*****
***
*def diamond(n):
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))
diamond(5)Output
*
***
*****
*******
*********
*******
*****
***
*4. Letter Pattern
Print letters in increasing alphabetical order per row.
A
AB
ABC
ABCD
ABCDEdef letter_triangle(n):
for i in range(1, n + 1):
print(" ".join(chr(65 + j) for j in range(i)))
letter_triangle(5)Output
A
A B
A B C
A B C D
A B C D E5. Number Pattern
Each row uses its row number.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5def number_triangle(n):
for i in range(1, n + 1):
print(" ".join([str(i)] * i))
number_triangle(5)Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 56. Fibonacci Triangle
Each row continues the Fibonacci sequence.
0
1 1
2 3 5
8 13 21 34
55 89 144 233 377def fibonacci_triangle(n):
a, b = 0, 1
for i in range(1, n + 1):
row = []
for _ in range(i):
row.append(str(a))
a, b = b, a + b
print(" ".join(row))
fibonacci_triangle(5)Output
0
1 1
2 3 5
8 13 21 34
55 89 144 233 3777. Binary Triangle
Alternating 1s and 0s.
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1def binary_triangle(n):
for i in range(1, n + 1):
print(" ".join(str((1 + i + j) % 2) for j in range(1, i + 1)))
binary_triangle(5)Output
1
0 1
1 0 1
0 1 0 1
1 0 1 0 18. Wave Pattern
A wave using stars and spaces.
* *
* *
* *
* *
*def wave(n):
for i in range(n):
for j in range(2 * n - 1):
if i == j or i + j == 2 * n - 2:
print("*", end="")
else:
print(" ", end="")
print()
wave(5)Output
* *
* *
* *
* *
*9. Double Hill Pattern
Two mirrored hills.
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******def double_hill(n):
for i in range(1, n + 1):
print("*" * i + " " * (2 * (n - i) + 1) + "*" * i)
double_hill(7)Output
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******10. Cross/Plus Pattern
A plus shape inside a grid.
*
*
*****
*
* def cross(n):
mid = n // 2
for i in range(n):
for j in range(n):
print("*" if i == mid or j == mid else " ", end="")
print()
cross(5)Output
*
*
*****
*
* Conclusion
These 10 patterns extend the earlier collection, covering matrix algorithms (spiral), Fibonacci, letter grids, and geometric shapes. Try combining two patterns into one program for extra practice.
Happy coding!

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →