Answer to Question #228696 in Python for srikanth

Question #228696
Number Diamond

Given an integer 

N as input, write a program to print a number diamond of 2*N -1 rows as shown below.

Note: There is a space after each number.

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

    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1
Sample Input 1
5
Sample Output 1
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1
Sample Input 2
4
Sample Output 2
   1 
  1 2 
 1 2 3 
1 2 3 4 
 1 2 3 
  1 2 
   1
sample input 3
15
sample output3
              1 
             1 2 
            1 2 3 
           1 2 3 4 
          1 2 3 4 5 
         1 2 3 4 5 6 
        1 2 3 4 5 6 7 
       1 2 3 4 5 6 7 8 
      1 2 3 4 5 6 7 8 9 
     1 2 3 4 5 6 7 8 9 10 
    1 2 3 4 5 6 7 8 9 10 11 
   1 2 3 4 5 6 7 8 9 10 11 12 
  1 2 3 4 5 6 7 8 9 10 11 12 13 
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 
  1 2 3 4 5 6 7 8 9 10 11 12 13 
   1 2 3 4 5 6 7 8 9 10 11 12 
    1 2 3 4 5 6 7 8 9 10 11 
     1 2 3 4 5 6 7 8 9 10 
      1 2 3 4 5 6 7 8 9 
       1 2 3 4 5 6 7 8 
        1 2 3 4 5 6 7 
         1 2 3 4 5 6 
          1 2 3 4 5 
           1 2 3 4 
            1 2 3 
             1 2 
              1
1
Expert's answer
2021-08-23T13:41:10-0400
n = int(input())
string_list=[]
for i in range(n):
    string = ''
    string += ' '*(n-(i+1))
    for k in range(1,i+2):
        string += str(k) + ' '
    string += ' '*(n-(i+2))
    string_list.append(string)
print('\n'.join(string_list))
print('\n'.join(string_list[-2::-1]))

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
APPROVED BY CLIENTS