用Python实现九九乘法表
2020-02-01 13:47
627 查看
1.用“#”组成的矩形的实现
代码
1 eight = int(input("Height:")) #用户输入高度 2 width = int(input("Width:")) #用户输入宽度 3 4 num_height = 1 5 while num_height <= height: 6 num_width = 1 7 while num_width <= width: 8 print("#",end="") 9 num_width += 1 10 print() 11 num_height += 1View Code
输出为
2.用“*”组成的三角形的实现
代码
1 m1 = 0 2 num2 = 0 3 4 height = int(input("height:")) 5 6 while num1 < height: 7 num1 += 1 8 while num2 < num1: 9 num2 += 1 10 print("*",end="") 11 print() 12 num2 = 0 13 """ 14 line = 5 15 while line > 0: 16 tmp = line 17 while tmp > 0: 18 print("*",end="") 19 tmp = tmp - 1 20 print() 21 line -= 1"""View Code
输出为
3.九九乘法表的实现
代码为
1 a = 0 #a为乘号左边数字 2 b = 0 #b为乘号右边数字 3 4 while b < 9: 5 b += 1 6 while a < b: 7 a += 1 8 print(str(a)+"*"+str(b)+"=",str(a * b),end=" ") 9 print() 10 a = 0View Code
输出为
发现排列有错位,经过改正后的代码为
1 a = 0 #a为乘号左边数字 2 b = 0 #b为乘号右边数字 3 4 while b < 9: 5 b += 1 6 while a < b: 7 a += 1 8 if (a * b > 9): 9 print(str(a)+"*"+str(b)+"=",str(a * b),end=" ") 10 else: 11 print(str(a)+"*"+str(b)+"=",str(a * b),"",end=" ")#print(a,"*",b,"=",str(a * b),"",end=" ") 12 print() 13 a = 0View Code
输出为
第二种修改方法为
1 a = 0 #a为乘号左边数字 2 b = 0 #b为乘号右边数字 3 4 while b < num: 5 b += 1 6 while a < b: 7 a += 1 8 print(str(a)+"*"+str(b)+"=",str(a * b),end="\t") 9 print() 10 a = 0View Code
“\t”表示在输出后面加上一个制表符。
转载于:https://www.cnblogs.com/bw13/p/5794138.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python实现不同格式打印九九乘法表
- Python实现不同格式打印九九乘法表
- 新手python实现九九乘法表
- python实现九九乘法表 (ver3.6)
- Python实现九九乘法表
- Python实现九九乘法表(数字和汉字版)
- python实现九九乘法表
- python 实现 九九乘法表【eclipse 编辑器】
- SHELL/Python实现九九乘法表
- 用python实现九九乘法表实例
- Python实现九九乘法表
- 九九乘法表Python实现
- python学习:质数判断、九九乘法表实现
- python实现不同格式的九九乘法表
- Python(for in / while)循环结构实现九九乘法表的五种效果
- Python实现不同格式打印九九乘法表
- Python用for循环实现九九乘法表
- python实现九九乘法表
- 用Python实现的九九乘法表
- Python实现不同格式打印九九乘法表