打印直角三角形
做个对比
代码
# 嵌套循环版本打印直角三角形
row = 1
while row <= 5:
col = 1
while col <= row:
print("*", end=' ')
col += 1
print()
row += 1
# python版本打印直角三角形
for i in range(1, 6):
print('* ' * i)
运行结果
两者均为
*
* *
* * *
* * * *
* * * * *