程序参考:n=int(input()) #输入边长for i in range(0,n): print((n-i)*' ',end='') if i==0: print(n*"*",end='') else: print("*",end='') print((n+2*i-2)*' ',end='') print("*",end='') print('');for i in range(n,-1,-1): print((n-i)*' ',end='') if i==0: print(n*"*",end='') else: print("*",end='') print((n+2*i-2)*' ',end='') print("*",end='') print(''); 结果