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
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) + ' ')
Comments
Leave a comment