python打印各種三角形
阿新 • • 發佈:2018-09-18
color spa -i style bsp light int 倒三角 print
# 打印左下角三角形:for i in range(10):之後,range(0,i)
# 打印右上角三角形:在左下角的基礎上,將"-"變成" "空格
for i in range(10): for j in range(0,i): print("-",end=" ") for j in range(i,10): print("$", end=" ") print("") print("-------------------------")
# 打印左上角三角形:for i in range(10):之後,range(0,10-i)
# 打印右下角三角形:在左上角的基礎上,將"-"變成" "空格
for i in range(10): for j in range(0, 10 - i): print("-", end=" ") for k in range(10 - i, 10): print("$", end=" ") print("")
打印上三角,只需要將"-",去掉
for i in range(10): for j in range(0, 10 - i): print(end=" ") for k in range(10 - i, 10): print("$", end=" ") print("")
- 打印倒三角,只需要將"-",去掉
for i in range(10): for j in range(0,i): print(end=" ") for j in range(i,10): print("$", end=" ") print("")
python打印各種三角形