Given an integer N, write a program to print a number diamond of 2*N-1 rows as shown below.
Explanation:
In the given example,the number of rows in the diamond is 4.
So,the output should be
. . . 0 . . .
. . 0 0 0 . .
. 0 0 0 0 0 .
0 0 0 0 0 0 0
. 0 0 0 0 0 .
. . 0 0 0 . .
. . . 0 . . .
print("Enter N: ", end='')
n = int(input())
k = 1
for i in range(1, n + 1):
point = '.' * (n - i)
nulls = '0' * k
print(point + nulls + point)
k += 2
k -= 4
for i in range(n, 1, -1):
point = '.' * (n - i + 1)
nulls = '0' * k
print(point + nulls + point)
k -= 2
Comments
Leave a comment