Answer to Question #302323 in Python for sruthi

Question #302323
program to print the diamond using 2*n-1 rows 

input:5

outpu:
. . . . 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 
. 0 0 0 0 0 0 0 . 
. . 0 0 0 0 0 . . 
. . . 0 0 0 . . . 
. . . . 0 . . . .

i want the output should be like this. i did not got the desired output by using the code which you have sent.




1
Expert's answer
2022-02-24T12:17:59-0500
n = 5

for i in range(1,n):    
    print ('.' * (n-i)  + '0' * (i*2-1) + '.' * (n-i))
for i in range(n,0,-1):
    print ('.' * (n-i)  + '0' * (i*2-1) + '.' * (n-i))

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