我想在python 2.7中创建空心三角形图案,就像这样
*
* *
* *
* *
* * * * *
我想我可以使用循环代码
line = 5
for i in range (line):
print (line-i) * " " + (line+1) * "* "
但输出是
*
* *
* * *
* * * *
* * * * *
有人帮我制作空心三角形吗? 谢谢。
答案 0 :(得分:0)
line = 5
print (line-1) * " " + "* "
for i in xrange(1,line-1):
print (line-i-1)* " " + "*" + (2*i -1)*" " + "* "
print (line) * "* "