Answer to Question #330337 in Python for sura karthik

Question #330337

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  


1
Expert's answer
2022-04-19T03:08:21-0400
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)




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