Answer to Question #301566 in Python for Sai

Question #301566

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





1
Expert's answer
2022-02-23T06:23:59-0500
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

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