1、用* 表示一个三角形
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 ## 倒三角形 2 line = 5 3 4 while line > 0: 5 i = line 6 while i > 0: 7 print('*',end="") 8 i -= 1 9 print() 10 line -= 1 11 12 ## 正三角形 13 14 line = 1 15 16 while line<=5: 17 i = line 18 while i>0: 19 print('*',end="") 20 i -= 1 21 print() 22 line += 1 23 ## 正三角形 24 25 line = 1 26 27 while line <=5: 28 tmp = 1 29 while tmp <= line: 30 print('*',end='') 31 tmp += 1 32 print() 33 line += 1
2、用*表示一个长方形
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #_author:Administrator 2 #date: 2018/1/6 3 4 height = int(input('高:')) 5 width = int(input('宽:')) 6 7 # num_height = 1 8 # while num_height <= height: 9 # num_width = 1 10 # while num_width <= 11 # print("*",end="") 12 # num_width += 1 13 # print() 14 # num_height += 1 15 16 while height > 0: 17 num_width = width 18 while num_width > 0: 19 print('*',end='') 20 num_width -= 1 21 print() 22 height -= 1
3、九九乘法表
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 fst = 1 2 3 while fst <= 9: 4 sec = 1 5 while sec <= fst: 6 print( str(fst) +'*' +str(sec) + '=' +str(sec * fst), end=' ') 7 sec += 1 8 print() 9 fst += 1