In this post, I am going to write a python script to print Diamond Star Pattern. I am writing this program in Python 3 version.
And, It’s a python console program to print a diamond star pattern. So let’s see.
print ("Enter the limit") rows = int(input()) #top half k = 0 for i in range(1, rows + 1): # print spaces for j in range (1, (rows - i) + 1): print(end = " ") # let's print stars while k != (2 * i - 1): print("*", end = "") k = k + 1 k = 0 # add a line break print() #bottom half k = 2 m = 1 for i in range(1, rows): # print spaces for j in range (1, k): print(end = " ") k = k + 1 # print star while m <= (2 * (rows - i) - 1): print("*", end = "") m = m + 1 m = 1 #add a line break print()
Read the inline comments to understand the program.
Sample output:
Enter the limit 6 * *** ***** ******* ********* *********** ********* ******* ***** *** *
Enjoy learning!
The post Python program to print Diamond Star pattern! appeared first on TutorialsMade.