Given an integer value
N as input, write a program to print a shaded diamond of 2*N -1 rows using an asterisk(*) character as shown below.
Note: There is a space after each asterisk (*) character.
Not sure what is meant by "shadowed", so 2 options:
Option 1:
n = int(input())
for i in range(1, n + 1):
print(('* ' * i).rjust(n + i))
for i in range(n - 1, 0, -1):
print(('* ' * i).rjust(n + i))
Option 2:
n = int(input())
for i in range(1, n + 1):
lst = [' '] * 2 * i
lst[0] = lst[-2] = '*'
print(''.join(lst).rjust(n + i))
for i in range(n - 1, 0, -1):
lst = [' '] * 2 * i
lst[0] = lst[-2] = '*'
print(''.join(lst).rjust(n + i))
Comments
Leave a comment