Print Diamond Pattern in Python of Stars using for loop
ADVERTISEMENTS
Print diamond pattern in python of stars using for loop. In this article, you will learn how to print diamond pattern in python of stars using the for loop.
Source Code
# Print Diamond Pattern in Python of Stars using for loop
x, c, k, s = None, None, None, 1
print ("-----Enter the number of rows-----")
x = int (input ())
s = x - 1
print ("\n-----The diamond pattern is-----\n")
for k in range (1, x + 1):
print (end="\t")
for c in range (1, s + 1):
print (end=" ")
s = s - 1
for c in range (1, (2 * k - 1) + 1):
print (end="*")
print (end="\n")
s = 1
for k in range (1, x + 1):
print (end="\t")
for c in range (1, s + 1):
print (end=" ")
s = s + 1
for c in range (1, (2 * (x - k) - 1) + 1):
print (end="*")
print (end="\n")
Output
-----Enter the number of rows-----
6
-----The diamond pattern is-----
*
***
*****
*******
*********
***********
*********
*******
*****
***
*