Monday, July 24, 2017

Rhombus Pattern - N Slashes Side


Given an odd value of N, the program must print a rhombus in diamond shape whose side contains N slashes as shown below in the examples.

Input Format:


The first line contains N.

Output Format:


The rhombus in diamond shape with each side containing N slashes. Asterisk is used as a filler for other values.

Boundary Conditions:1 <= N <= 101 and N is odd.

Example Input/Output 1:
Input:
5

Output:
****/\****
***/**\***
**/****\**
*/******\*
/********\
\********/
*\******/*
**\****/**
***\**/***
****\/****
 

Solution - 1:
n = int(input())
for i in range(2*n):
    for j in range(2*n):
        if i<n and j==n-i-1:
            print('/',end='')
        elif i<n and j==n+i:
            print('\\',end='')
        elif i>=n and j==i-n:
            print('\\',end='')
        elif i>=n and j==3*n-i-1:
            print('/',end='')
        else:
            print('*',end='')
    print()

Solution - 2:  

n = int(input())
print('\n'.join(('/'+'**'*i+'\\').center(2*n,'*') if i< n else ('\\'+'**'*(2*n-i-1)+'/').center(2*n,'*') for i in range(2*n)))
Share: