简单的for循环打印三角形
1,for循环方法实现星星三角 * * * * * * * * * * * * 代码: for i in range(0,5): for j in
range(i+1): if i == 4: print("* ",end="") continue if j == 0 or j == i:
print("* ",end="") else: print(" ",end="") print() 2.实心三角:
*
* *
* * *
* * * *
* * * * *
for i in range(5): print("* " * (i+1))
3.实心正方形
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
for i in range(5): print("* "*5) print()
4.空心正方形
* * * * *
* *
* *
* *
* * * * *
for i in range(5): print("* "*5) print() for i in range(4): if i == 0:
print("* " * 5) if i ==3: print("* " * 5) continue for j in range(5): if j ==
0: print("* ",end=" ") if j == 4: print("* ") else: print(" ",end="")
5.金字塔:
*
* *
* * *
* * * *
* * * * *
for i in range(5): print(" "*(4-i),end="") print(" * "*(i+1))
刚开始学习,博客写得不是很好。
热门工具 换一换