Answer to Question #225959 in Python for ganesh

Question #225959

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

Note: There is a space after each number


1
Expert's answer
2021-08-13T16:13:46-0400
n = int(input())
for i in range(0, n):
    print(' '.join([str(abs(x) % 10) for x in range(-i, i + 1)]).rjust(2 * (n + i) - 1) + ' ')
for i in range(n - 2, -1, -1):
    print(' '.join([str(abs(x) % 10) for x in range(-i, i + 1)]).rjust(2 * (n + 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