Given an integer N as input, write a program to print a number diamond of 2*N 1 rows as shown below. Note: There is a space after each number. Input The first line of input is an integer N . Explanation In the given example, the number of rows in the diamond is 5 . So, the output should be Sample Input 1 5 Sample Output 1 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 1 2 3 1 2
n = int(input())
diamond = []
for i in range(n,0,-1):
tmp = [j+1 for j in range(i)]
if not diamond:
diamond.append(tmp)
else:
tmp = [" "*(n-i-1)] + tmp
diamond = [tmp] + diamond + [tmp]
for row in diamond:
print(*row)
Comments
Leave a comment