Answer to Question #243089 in Python for balu

Question #243089

Diamond

Given an integer value

N, write a program to print a number diamond of 2*N -1 rows as shown below.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

....0....

...000...

..00000..

.0000000.

000000000

.0000000.

..00000..

...000...

....0....


1
Expert's answer
2021-09-27T15:46:47-0400
def diamond_shape(number):
    x = 0
    for row in range(1, number + 1):
        for col in range (1, (number - row) + 1):
            print(end = " ")
         
        while x != (2 * row - 1):
            print("0", end = "")
            x = x + 1
        x = 0
        print()
 
    k = 1
    x = 1
    for row in range(1, number):
        for col in range (1, k + 1):
            print(end = " ")
        k = k + 1
        while x <= (2 * (number - row) - 1):
            print("0", end = "")
            x = x + 1
        x = 1
        print()
 
number=int(input())
diamond_shape(number)
    
    







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