1,直角三角形
""" *
**
***
****
*****
******
"""
layer = int(input("请输入您要打印的层数:"))
for i in range(1,layer+1):
for j in range(1,i+1):
print("*",end="")
print()
"""
*
***
*****
*******
"""
layer = int(input("请输入您要打印的层数:"))
for i in range(1,layer):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
print("*", end="")
# 一行结束了,可以换行了
print("")
"""
*********
*******
*****
***
*
"""
layer = int(input("请输入您要打印的层数:"))
for i in range(layer,0,-1):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
print("*", end="")
# 一行结束了,可以换行了
print("")
"""
*
***
*****
*******
*********
*******
*****
***
*
"""
layer = int(input("请输入您要打印的层数:"))
while layer % 2 ==0:
layer=int(input("对不起,层数必须是奇数层:"))
#上半层
for i in range(1,layer//2 + 2):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
print("*", end="")
# 一行结束了,可以换行了
print("")
#下半层
for i in range(layer//2,0,-1):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
print("*", end="")
# 一行结束了,可以换行了
print("")
"""
*
* *
* *
* *
* *
* *
* *
* *
*
"""
layer = int(input("请输入您要打印的层数:"))
while layer % 2 ==0:
layer=int(input("对不起,层数必须是奇数层:"))
#上半层
for i in range(1,layer//2 + 2):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
if j ==1 or j==star_num:
print("*", end="")
else:
print(" ",end="")
# 一行结束了,可以换行了
print("")
#下半层
for i in range(layer//2,0,-1):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
if j ==1 or j==star_num:
print("*", end="")
else:
print(" ",end="")
# 一行结束了,可以换行了
print("")
"""
*
***
* * *
* * *
*********
* * *
* * *
***
*
"""
layer = int(input("请输入您要打印的层数:"))
while layer % 2 ==0:
layer=int(input("对不起,层数必须是奇数层:"))
#上半层
for i in range(1,layer//2 + 2):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
if j ==1 or j==star_num or j == (star_num +1)//2 or i == layer//2+1:
print("*", end="")
else:
print(" ",end="")
# 一行结束了,可以换行了
print("")
#下半层
for i in range(layer//2,0,-1):
# 先计算空格的数量
space_num = layer - i
for j in range(1, space_num + 1):
print(" ", end="")
# 计算*的数量
star_num = 2 * i - 1
for j in range(1, star_num + 1):
if j ==1 or j==star_num or j == (star_num +1)//2:
print("*", end="")
else:
print(" ",end="")
# 一行结束了,可以换行了
print("")