Diamond with Plus Pattern

The program must accept an integer N as the input. The program must print (2*N)-1 lines of pattern as shown in the Example Input/Output section. The asterisks in the pattern indicate the diamond and plus symbols. The hyphens in the pattern indicate the empty spaces.

Boundary Condition(s):
2 <= N <= 50

Input Format:
The first line contains N.

Output Format:
The first (2*N)-1 lines contain the desired pattern as shown in the Example Input/Output section.

Example Input/Output 1:
Input:
5

Output:
--------*
------*-*-*
----*---*---*
--*-----*-----*
*-*-*-*-*-*-*-*-*
--*-----*-----*
----*---*---*
------*-*-*
--------*

Explanation:
Here N=5, so the pattern contains 9 lines ((2*5)-1) of output.

Example Input/Output 2:
Input:
3

Output:
----*
--*-*-*
*-*-*-*-*
--*-*-*
----*

Example Input/Output 3:
Input:
6

Output:
----------*
--------*-*-*
------*---*---*
----*-----*-----*
--*-------*-------*
*-*-*-*-*-*-*-*-*-*-*
--*-------*-------*
----*-----*-----*
------*---*---*
--------*-*-*
----------*
n=int(input())
l=[]
s='-'*(2*(n-1))+'*'
l.append(s)
val=1
for i in range(n-2,0,-1):
    s='-'*(2*i)+'*'
    s+=('-'*val)
    s+='*'
    s+=('-'*val)
    s+='*'
    l.append(s)
    val+=2
s='*-'*((2*n)-1)
l.append(s[:-1])
for i in l:
    print(i)
for i in l[:-1][::-1]:
    print(i)
Previous Article

Form List of Integers

Next Article

Alternate Conversion Octal and Hexadecimal

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *