*
***
*****
*******
*****
***
*
layer = int(input("请输入要打印的行数:"))
while layer % 2 == 0:
layer = int(input("请输入正确的要打印的行数,注意是奇数行:"))
#上半部分
for i in range(1,layer // 2 + 2):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
print("*",end="")
print("")
#下半部分
for i in range(layer // 2 ,0,-1):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
print("*",end="")
print("")
*
* *
* *
* *
* *
* *
*
layer = int(input("请输入要打印的行数:"))
while layer % 2 == 0:
layer = int(input("请输入正确的要打印的行数,注意是奇数行:"))
#上半部分
for i in range(1,layer // 2 + 2):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1:
print("*",end="")
else :
print(" ",end = "")
print("")
#下半部分
for i in range(layer // 2 ,0,-1):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1:
print("*",end="")
else :
print(" ",end="")
print("")
*
* *
* *
******
* *
* *
*
layer = int(input("请输入要打印的行数:"))
while layer % 2 == 0:
layer = int(input("请输入正确的要打印的行数,注意是奇数行:"))
#上半部分
for i in range(1,layer // 2 + 2):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1 or i == layer // 2 + 1:
print("*",end="")
else :
print(" ",end = "")
print("")
#下半部分
for i in range(layer // 2 ,0,-1):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1:
print("*",end="")
else :
print(" ",end="")
print("")
*
***
* * *
*******
* * *
***
*
layer = int(input("请输入要打印的行数:"))
while layer % 2 == 0:
layer = int(input("请输入正确的要打印的行数,注意是奇数行:"))
#上半部分
for i in range(1,layer // 2 + 2):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1 or i == layer // 2 + 1 or j == star_num // 2:
print("*",end="")
else :
print(" ",end = "")
print("")
#下半部分
for i in range(layer // 2 ,0,-1):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1 or j == star_num // 2:
print("*",end="")
else :
print(" ",end="")
print("")
*
***
* * *
*******
*
*
*
layer = int(input("请输入要打印的行数:"))
while layer % 2 == 0:
layer = int(input("请输入正确的要打印的行数,注意是奇数行:"))
#上半部分
for i in range(1,layer // 2 + 2):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == 0 or j == star_num - 1 or i == layer // 2 + 1 or j == star_num // 2:
print("*",end="")
else :
print(" ",end = "")
print("")
#下半部分
for i in range(layer // 2 ,0,-1):
#计算空格的个数
spce_num = layer - i
for j in range(0,spce_num):
print(" ",end="")
#计算*个数
star_num = 2 * i - 1
for j in range(0,star_num):
if j == star_num // 2:
print("*",end="")
else :
print(" ",end="")
print("")