【学习打卡--Python3】打印一个空心菱形图案

# 打印一个空心菱形图案--python3.5解释器中调试通过
row = 1# 当前行
total_row = int(input("请输入总行数:"))# 总行数
half = (total_row + 1) / 2# 一半
while row <= total_row:
col = 1
while col <= total_row:
if (col == half-(row - 1) or col == total_row + 1 - (half-(row - 1))
or col == half - ((total_row + 1) - row - 1)
or col == total_row + 1 - (half - ((total_row + 1) - row - 1))):
print("*", end="")
else:
print(" ", end="")
col += 1
print("")
row += 1
结果如下:
【【学习打卡--Python3】打印一个空心菱形图案】【学习打卡--Python3】打印一个空心菱形图案
文章图片

    推荐阅读