Suppose we have a number n. We have to draw a diamond pattern with asterisks with 2n-1 lines. First 1 to n lines contain 1 to n number of asterisks, and next they are decreasing from n-1 to 1.
So, if the input is like n = 5, then the output will be
* * * * * * * * * * * * * * * * * * * * * * * * *
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding
def solve(n): for i in range(1,n+1): print(('* '*i).center(2*n-1)) for i in range(n-1,0, -1): print(('* '*i).center(2*n-1)) n = 10 solve(n)
10
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *