📜  奇数行之间有间隙的菱形的 python 代码 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:15.193000             🧑  作者: Mango

代码示例1
//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))