Answer to Question #284432 in Python for Bannu

Question #284432

Number Diamond




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
2022-01-03T10:46:37-0500
rows = int(input("Enter the number of rows: "))  
 
k = 2 * rows - 2  
print('Result: ') 
for i in range(0, rows):  
    for j in range(0, k):  
        print(end=" ")  
    k = k - 1  
    for j in range(1, i + 1):  
        print(j, end=" ")  
    print("")  
  
k = rows - 2  
for i in range(rows, -1, -1):  
    for j in range(k, 0, -1):  
        print(end=" ")  
    k = k + 1  
    for j in range(1, i + 1):  
        print(j, end=" ")  
    print("")

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