# Top 18 Python Pattern Programs You Must Know About [Snippets]

### We’ve sorted a list of multiple ideas for pattern printing in Python to start your preparations with multiple kinds of Python pattern programs in this list.

· Web Dev Zone · Code Snippet
Save
7.39K Views

Preparing for technical interviews takes a lot of preparation, and it’s highly probable that you might have to create Python pattern programs there. That’s why we’ve sorted a list of multiple ideas for pattern printing in Python to start your preparations.

We have multiple kinds of Python pattern programs in this list, so choose your expertise and experience. Make sure that you understand what part of code does what before you move onto the next pattern. Without a proper understanding of how the system works, you would face a lot of difficulty in explaining its working.

Many times, the interviewer asks for an explanation of how you performed pattern printing in Python. Knowing how everything works will help you in answering those questions effectively.

You’ll find the Python code along with every pattern below:

## Pattern #1: Simple Number Triangle Pattern

Pattern:

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

Code:

Python

x
11
9

1
`rows = 6`
2
`for num in range(rows):`
3
`    for i in range(num):`
4
`        print(num, end=” “) # print number`
5
`    # line after each row to display pattern correctly`
6
`    print(” “)`

## Pattern #2: Inverted Pyramid of Numbers

Pattern:

1 1 1 1 1

2 2 2 2

3 3 3

4 4

5

Code:

Python

`xxxxxxxxxx`
1
13
9

1
`rows = 5`
2
`b = 0`
3
`for i in range(rows, 0, -1):`
4
`    b += 1`
5
`    for j in range(1, i + 1):`
6
`        print(b, end=’ ‘)`
7
`    print(‘\r’)`

## Pattern #3: Half Pyramid Pattern of Numbers

Pattern:

1 2

1 2 3

1 2 3 4

1 2 3 4 5

Code:

Python

`x`

1
`rows = 5`
2
`for row in range(1, rows+1):`
3
`    for column in range(1, row + 1):`
4
`        print(column, end=’ ‘)`
5
`    print(“”)`

## Pattern #4: Inverted Pyramid of Descending Numbers

Pattern:

5 5 5 5 5

4 4 4 4

3 3 3

2 2

1

Code:

Python

`xxxxxxxxxx`
1
11
9

1
`rows = 5`
2
`for i in range(rows, 0, -1):`
3
`    num = i`
4
`    for j in range(0, i):`
5
`        print(num, end=’ ‘)`
6
`    print(“\r”)`

## Pattern #5: Inverted Pyramid of the Same Digit

Pattern:

5 5 5 5 5

5 5 5 5

5 5 5

5 5

5

Code:

Python

`xxxxxxxxxx`
1
11
9

1
`rows = 5`
2
`num = rows`
3
`for i in range(rows, 0, -1):`
4
`    for j in range(0, i):`
5
`        print(num, end=’ ‘)`
6
`    print(“\r”)`

## Pattern #6: Reverse Pyramid of Numbers

Pattern:

2 1

3 2 1

4 3 2 1

5 4 3 2 1

Code:

Python

`xxxxxxxxxx`
1

1
`rows = 6`
2
`for row in range(1, rows):`
3
`    for column in range(row, 0, -1):`
4
`        print(column, end=’ ‘)`
5
`    print(“”)`

## Pattern #7: Inverted Half Pyramid Number Pattern

Pattern:

0 1 2 3 4 5

0 1 2 3 4

0 1 2 3

0 1 2

0 1

Code:

Python

`xxxxxxxxxx`
1

1
`rows = 5`
2
`for i in range(rows, 0, -1):`
3
`    for j in range(0, i + 1):`
4
`        print(j, end=’ ‘)`
5
`    print(“\r”)`

## Pattern #8: Pyramid of Natural Numbers Less Than 10

Pattern:

2 3 4

5 6 7 8 9

Code:

Python

`xxxxxxxxxx`
1
17
9

1
`currentNumber = 1`
2
`stop = 2`
3
`rows = 3 # Rows you want in your pattern`
4
`for i in range(rows):`
5
`    for column in range(1, stop):`
6
`        print(currentNumber, end=’ ‘)`
7
`        currentNumber += 1`
8
`    print(“”)`
9
`    stop += 2`

## Pattern #9: Reverse Pattern of Digits from 10

Pattern:

1

3 2

6 5 4

10 9 8 7

Code:

Python

`xxxxxxxxxx`
1
11

1
`start = 1`
2
`stop = 2`
3
`currentNumber = stop`
4
`for row in range(2, 6):`
5
`    for col in range(start, stop):`
6
`        currentNumber -= 1`
7
`        print(currentNumber, end=’ ‘)`
8
`    print(“”)`
9
`    start = stop`
10
`    stop += row`
11
`    currentNumber = stop`

## Pattern #10: Unique Pyramid Pattern of Digits

Pattern:

1 2 1

1 2 3 2 1

1 2 3 4 3 2 1

1 2 3 4 5 4 3 2 1

Code:

Python

`xxxxxxxxxx`
1
13
9

1
`rows = 6`
2
`for i in range(1, rows + 1):`
3
`    for j in range(1, i – 1):`
4
`        print(j, end=” “)`
5
`    for j in range(i – 1, 0, -1):`
6
`        print(j, end=” “)`
7
`    print()`

## Pattern #11: Connected Inverted Pyramid Pattern of Numbers

Pattern:

5 4 3 2 1 1 2 3 4 5

5 4 3 2 2 3 4 5

5 4 3 3 4 5

5 4 4 5

5 5

Code:

Python

`xxxxxxxxxx`
1
17
9

1
`rows = 6`
2
`for i in range(0, rows):`
3
`    for j in range(rows – 1, i, -1):`
4
`        print(j, ”, end=”)`
5
`    for l in range(i):`
6
`        print(‘ ‘, end=”)`
7
`    for k in range(i + 1, rows):`
8
`        print(k, ”, end=”)`
9
`    print(‘\n’)`

## Pattern #12: Even Number Pyramid Pattern

Pattern:

10

10 8

10 8 6

10 8 6 4

10 8 6 4 2

Code:

Python

`xxxxxxxxxx`
1
17
9

1
`rows = 5`
2
`LastEvenNumber = 2 * rows`
3
`evenNumber = LastEvenNumber`
4
`for i in range(1, rows+1):`
5
`    evenNumber = LastEvenNumber`
6
`    for j in range(i):`
7
`        print(evenNumber, end=’ ‘)`
8
`        evenNumber -= 2`
9
`    print(“\r”)`

## Pattern #13: Pyramid of Horizontal Tables

Pattern:

0

0 1

0 2 4

0 3 6 9

0 4 8 12 16

0 5 10 15 20 25

0 6 12 18 24 30 36

Code:

Python

`xxxxxxxxxx`
1

1
`rows = 7`
2
`for i in range(0, rows):`
3
`    for j in range(0, i + 1):`
4
`        print(i * j, end=’ ‘)`
5
`    print()`

## Pattern #14: Pyramid Pattern of Alternate Numbers

Pattern:

3 3

5 5 5

7 7 7 7

9 9 9 9 9

Code:

Python

`xxxxxxxxxx`
1
17
9

1
`rows = 5`
2
`i = 1`
3
`while i <= rows:`
4
`    j = 1`
5
`    while j <= i:`
6
`        print((i * 2 – 1), end=” “)`
7
`        j = j + 1`
8
`    i = i + 1`
9
`    print()`

## Pattern #15: Mirrored Pyramid (Right-angled Triangle) Pattern of Numbers

Pattern:

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

Code:

Python

`xxxxxxxxxx`
1
19

1
`rows = 6`
2
`for row in range(1, rows):`
3
`    num = 1`
4
`    for j in range(rows, 0, -1):`
5
`        if j > row:`
6
`            print(” “, end=’ ‘)`
7
`        else:`
8
`            print(num, end=’ ‘)`
9
`            num += 1`
10
`    print(“”)`

## Pattern #16: Equilateral Triangle with Stars (Asterisk Symbol)

Pattern:

*

* *

* * *

* * * *

* * * * *

* * * * * *

* * * * * * *

Code:

Java

`xxxxxxxxxx`
1
21

1
`print(“Print equilateral triangle Pyramid using stars “)`
2
`size = 7`
3
`m = (2 * size) – 2`
4
`for i in range(0, size):`
5
`    for j in range(0, m):`
6
`        print(end=” “)`
7
`    m = m – 1 # decrementing m after each loop`
8
`    for j in range(0, i + 1):`
9
`        # printing full Triangle pyramid using stars`
10
`        print(“* “, end=’ ‘)`
11
`    print(” “)`

## Pattern #17: Downward Triangle Pattern of Stars

Pattern:

* * * * * *

* * * * *

* * * *

* * *

* *

*

Code:

Python

`xxxxxxxxxx`
1
17
9

1
`rows = 5`
2
`k = 2 * rows – 2`
3
`for i in range(rows, -1, -1):`
4
`    for j in range(k, 0, -1):`
5
`        print(end=” “)`
6
`    k = k + 1`
7
`    for j in range(0, i + 1):`
8
`        print(“*”, end=” “)`
9
`    print(“”)`

## Pattern #18: Pyramid Pattern of Stars

Pattern:

* *

* * *

* * * *

* * * * *

Code:

Python

`xxxxxxxxxx`
1

1
`rows = 5`
2
`for i in range(0, rows):`
3
`    for j in range(0, i + 1):`
4
`        print(“*”, end=’ ‘)`
5
`    print(“\r”)`

Topics:
python, python programming, pattern, tutorial, code snippets

Published at DZone with permission of Shriram K.

Opinions expressed by DZone contributors are their own.

Comments