python打印三角形
python打印各种三角形
# 打印左下角三角形: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("")