Pages

Wednesday, 20 January 2016

Hollow Diamond Of Asterick '*'

# To print a Hollow diamond of Asterick '*'
# Set your font type As Courier

n=int(raw_input("Enter a no"))
x,y=" ","*"
n=(n-1)/2
b=2
q=-1
m,o=n,n
print (m+1)*x,y
for i in range(n) :
    a=n*x
    n=n-1
    p=q*x
    q=q+1
    if q==0 :
        print a,y,y
    else :
        print a,y,p,p,y
for j in range(m,0,-1) :
    c=b*x
    b=b+1
    r=(m-3)*x
    m=m-1
    if m==0:
        print (o+1)*x,y
    elif m==1 :
        print (o)*x,y,y
    else :
        print c,y,r,r,y

Output
Enter a number 9
      *
     * *
    *   *
   *     *
  *       *
   *     *
    *   *
     * *
      *