layer = int(input("请输入你要打印的行数:")) for i in range(1,layer+1): #计算空格的个数 space_num = layer - i for j in range(0,space_num): print(" ",end="") #计算*个数 star_num = 2*i-1 for j in range(0,star_num): print("*",end="") print("")