Pages

Wednesday, 20 January 2016

Diamond number 1

# 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 k in range(1,i) :
        print k,
    for l in range(i,0,-1) :
        print l,
    print
for i in range(n,-1,-1) :
    for j in range(0,w+2) :
        print " ",
    w=w+1
    for k in range(1,i) :
        print k,
    for l in range(i,0,-1) :
        print l,
    print

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