Given an integer value N as input, write a program to print a shaded diamond 2*N -1 rows using an asterisk ( * ).
Note: There is a space after each asterisk ( * ) character.
Example N = 5. There for the output should be:
*
* *
* * *
* * * *
* * * * *
* *
* *
* *
*
N = int(input())
diamond = []
for i in range(1, N + 1):
line = ' '.join(['*' for x in range(i)])
diamond.append(line.center(2 * N, ' '))
for i in range(N - 1, 0, -1):
line = ' '.join(['*' for x in range(i)])
if i == 1:
line = line[::-2]
diamond.append(line.center(2 * N, ' '))
print('\n'.join(diamond))
Comments
Leave a comment