a = 2 * eval(input("输入金字塔层数:")) for i in range(1, a+1, 2): b = (a-i)//2 # 去尾 print(' '*b, '*'*i) 每行有奇数个星号组成。