Pages

Wednesday, 20 January 2016

Diamond Number 2

# To print a diamond of numbers
# Set your font type As Courier

n=int(raw_input("Enter a number"))
n=(n)/2
w=n
for i in range(1,n+2) :
    for j in range(w,0,-1) :
        print " ",
    w=w-1
    for l in range(i,0,-1) :
        print l,
    for k in range(2,i+1) :
        print k,

    print
for i in range(n,-1,-1) :
    for j in range(0,w+2) :
        print " ",
    w=w+1
    
    for l in range(i,0,-1) :
        print l,
    for k in range(2,i+1) :
        print k,
    print

Output
Enter a number 9
        1
      2 1 2
    3 2 1 2 3
  4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
  4 3 2 1 2 3 4
    3 2 1 2 3
      2 1 2
        1