打印等腰直角三角形
for i in range(1, 5):
for j in range(1, 5):
if j>=i:
print " * ",
print "\n"
* * * *
* * *
* *
*
打印实心三角形
for i in range(1, 6):
for j in range(0, 6 - i):
print " ",
for k in range(1, i + 1):
print " * ",
print "\n"
*
* *
* * *
* * * *
* * * * *
打印空心三角形
rows = 5
for i in range(0, rows + 1):
for j in range(0, rows - i):
print " ",
for k in range(0, 2 * i - 1):
if k == 0 or k == 2 * i - 2 or i == rows:
print "*",
else:
print " ",
print "\n"
*
* *
* *
* *
* * * * * * * * *