Pythondex
Python Pattern Programs

Print Diamond Pattern In Python

Last updated March 7, 2024 by Jarvis Silva

In this tutorial. I will show you the python program to print Diamond pattern, printing patterns in python is fun and very interesting, we will create this program using both for loop and while loop you can use any program you want.

Python Program To Print Diamond Pattern Using For Loop


rows = int(input("Enter Diamond Pattern Rows: "))

k = 0

for i in range(1, rows + 1):
    for j in range(1, rows - i + 1):
        print(end = ' ')
    while k != 2 * i - 1:
        print('#', end = '')
        k = k + 1
    k = 0
    print()

k = 2
l = 1

for i in range(1, rows):
    for j in range(1, k):
        print(end = ' ')
    k = k + 1
    while l <= (2 * (rows - i) - 1):
        print('#', end = '')
        l = l + 1
    l = 1
    print()

Python Program To Print Diamond Pattern Using While Loop


rows = int(input("Enter Diamond Pattern Rows: "))

k = 0
i = 1

while(i < rows):
    for j in range(1, rows - i + 1):
        print(end = ' ')
    while k != 2 * i - 1:
        print('#', end = '')
        k = k + 1
    k = 0
    print()
    i = i + 1

k = 2
l = 1

i = 1

while(i < rows):
    for j in range(1, k):
        print(end = ' ')
    k = k + 1
    while l <= (2 * (rows - i) - 1):
        print('#', end = '')
        l = l + 1
    l = 1
    print()
    i = i + 1

Above are the programs for print diamond patterns using loops. Now to run this programs you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer.

Don’t want to create all the files and folders then you can run this program now using this online python compiler it is fast and easy.

After running this program you will see a diamond pattern printed like below output. The output would be same for both for and while loop programs.


Enter Diamond Pattern Rows: 5
    #
   ###
  #####
 #######
#########
 #######
  #####
   ###
    #

I hope you found this tutorial helpful and useful. Do share this tutorial with your friends who might be interested in this program.

Here are some more python drawing tutorials for you:

I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂