Answer to Question #226146 in Python for GANESH

Question #226146

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-16T05:48:54-0400
n = int(input())


for i in range(n):
	s = ' '*(n - i - 1)
	s += '* '* (i + 1)
	print(s)
for j in range(n-1):
	s = ' '*(j + 1)
	s += '*' + ' '*(n - (2*j)) + '*'
	if j == (n - 2):
		s = ' '*(n - 1) + '*'
	print(s)

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