Answer to Question #225792 in Python for Ankita

Question #225792

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.


1
Expert's answer
2021-08-13T16:13:02-0400
N = int(input())

rows = []
for number in range(1, N + 1):
    rows.append(' '.join(['*' for _ in range(1, number + 1)]))
for number in rows[::-1][1::]:
    rows.append(number)
diamond = '\n'.join([x.center(2* N - 1) for x in rows])
print(diamond)

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