Answer to Question #245114 in Python for Raju

Question #245114

Shaded Diamond

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-10-05T13:24:10-0400
print("Input value of n (odd):")
n=int(input())       
x=n//2+1       
for i,j in zip(range(1,x+1),range(1,n+1,2)):   
    print(' '*(x-i)+'*'*(j))
for i,j in zip(range(1,x+1),range(n-2,-1,-2)):
    print(' '*(i)+'*'*(j))

Sample input 1:
5
Sample Output 1:
  *
 ***
*****
 ***
  *

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
New on Blog
APPROVED BY CLIENTS