Answer to Question #226145 in Python for ganesh

Question #226145

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 

   1 2 

  1 2 3 

  1 2 3 4 

1 2 3 4 5 

 1 2 3 4 

  1 2 3 

   1 2 

    1

  


1
Expert's answer
2021-08-16T01:04:11-0400
N = int(input("Enter the number of N: "))  
  
n = 2 * N - 2  
for i in range(0, N):  
    for j in range(0, n):  
        print(end=" ")  
    n = n - 1  
    for j in range(1, i + 1):  
        print(j, end=" ")  
    print("")  
  


n = N - 2  
for i in range(N, -1, -1):  
    for j in range(n, 0, -1):  
        print(end=" ")  
    n = n + 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