1.打印矩形
2.打印左直角三角形
3.打印右直角三角形
4.打印等腰三角形
5.打印倒三角形
# 矩形
for i in range(0, 3):
for j in range(0, 5):
print("1 ", end='')
print('')
-----------------------------
#1 1 1 1 1
#1 1 1 1 1
#1 1 1 1 1
# 左直角三角形
# 方式一:
for i in range(0, 5):
for j in range(0, i+1):
print('2', end='')
print('')
# 方式二:
for i in range(1, 6):
for j in range(1, i+1):
print('', end='')
print('3'*i)
---------------------------
#2
#22
#222
#2222
#22222
#3
#33
#333
#3333
#33333
# 右直角三角形
for i in range(1, 6):
for j in range(1, 6-i):
print(' ', end='')
print('4'*i)
-------------------------
# 4
# 44
# 444
# 4444
#44444
# 等腰三角形
# 方式一
for i in range(1, 6):
for j in range(1, 6-i):
print(" ", end="")
print("5 "*i)
# 方式二:
for i in range(1, 6):
for j in range(1, 6-i):
print(' ', end='')
for k in range(1, i+1):
print('6 ', end='')
print('')
---------------------------------
# 5
# 5 5
# 5 5 5
# 5 5 5 5
#5 5 5 5 5
# 6
# 6 6
# 6 6 6
# 6 6 6 6
#6 6 6 6 6
# 倒三角形
for i in range(0, 5):
for j in range(1, i+1):
print(' ', end='')
for k in range(0, 5-i):
print('7 ', end='')
print('')
-------------------------------
#7 7 7 7 7
# 7 7 7 7
# 7 7 7
# 7 7
# 7