Answer to Question #266314 in Python for Bayernmunich

Question #266314

Given an integer N as input, write a program to print a number diamond of 2*N -1 rows.


The number of rows in the diamond is 5.

So the output should be.


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-11-17T17:39:45-0500
def NuMofDiamond(N):

    

# loop for creating upper part of the diamond

  for i in range(N):

  

    for dim in range(0, i + 1):

      print("1 ", end = "")

    print()

  

  #loop for creating loower part of the diamond

  for i in range(1, N):

  

    for dim in range(i, N):

      print("1 ", end = "")

    print()

  




N = 5

  

# Calling a function

NuMofDiamond(N)

  

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