Answer to Question #225793 in Python for Ankita

Question #225793

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.


1
Expert's answer
2021-08-14T01:40:07-0400

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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS