Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python code for diamond with gap between odd rows

//pgm for diamond pattern
print("Give the value of n(odd):")
n=int(input())        //input from the user is stored in n
x=n//2+1
//here two loops are combined into one by 'zip'
//loop for printing the first half diamond              
for i,j in zip(range(1,x+1),range(1,n+1,2)):   
    print(' '*(x-i)+'*'*(j))
//loop for printing the second half diamond(reverse half)
for i,j in zip(range(1,x+1),range(n-2,-1,-2)):
    print(' '*(i)+'*'*(j))
Source by geekstocode.com #
 
PREVIOUS NEXT
Tagged: #python #code #diamond #gap #odd #rows
ADD COMMENT
Topic
Name
6+8 =