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....


Expert's answer

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)
    
    







LATEST TUTORIALS
APPROVED BY CLIENTS