Answer to Question #220406 in Python for janardhan

Question #220406

Given an integer N as input, write a program to print a number diamond of 2*N -1 rows as shown below.


1
Expert's answer
2021-07-25T08:39:39-0400
n      = int(input('N:'))

prefix = ' ' * (n - 1)
ast    = '*'

for i in range(1, n):
  print(' ' * (n - i), end='')
  print('*' * (2 * i - 1))

for i in range(n, 0, -1):
  print(' ' * (n - i), end='')
  print('*' * (2 * i - 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