用Python实现九九乘法表
1.用“#”组成的矩形的实现
代码
eight = int(input("Height:")) #用户输入高度
width = int(input("Width:")) #用户输入宽度
num_height = 1
while num_height <= height:
num_width = 1
while num_width <= width:
print("#",end="")
num_width += 1
print()
num_height += 1
输出为

2.用“*”组成的三角形的实现
代码
m1 = 0
num2 = 0 height = int(input("height:")) while num1 < height:
num1 += 1
while num2 < num1:
num2 += 1
print("*",end="")
print()
num2 = 0
"""
line = 5
while line > 0:
tmp = line
while tmp > 0:
print("*",end="")
tmp = tmp - 1
print()
line -= 1"""
输出为

3.九九乘法表的实现
代码为
a = 0 #a为乘号左边数字
b = 0 #b为乘号右边数字 while b < 9:
b += 1
while a < b:
a += 1
print(str(a)+"*"+str(b)+"=",str(a * b),end=" ")
print()
a = 0
输出为

发现排列有错位,经过改正后的代码为
a = 0 #a为乘号左边数字
b = 0 #b为乘号右边数字 while b < 9:
b += 1
while a < b:
a += 1
if (a * b > 9):
print(str(a)+"*"+str(b)+"=",str(a * b),end=" ")
else:
print(str(a)+"*"+str(b)+"=",str(a * b),"",end=" ")#print(a,"*",b,"=",str(a * b),"",end=" ")
print()
a = 0
输出为

第二种修改方法为
a = 0 #a为乘号左边数字
b = 0 #b为乘号右边数字 while b < num:
b += 1
while a < b:
a += 1
print(str(a)+"*"+str(b)+"=",str(a * b),end="\t")
print()
a = 0
“\t”表示在输出后面加上一个制表符。
用Python实现九九乘法表的更多相关文章
- 用Python编写九九乘法表考虑print自动换行问题
编写了一个简单的小程序九九乘法表,代码如下: for i in range(1,10): for j in range(1,i+1): print(" %d*%d=%d" % (j ...
- python打印九九乘法表
每种编程语言都可能会遇到编写“九九乘法表”的问题,用Python来处理也是很简单的,具体代码如下(基于Python3)): i = 1 while i <= 9: j = 1 while j & ...
- python编写九九乘法表代码
打印九九乘法表 代码: #!/usr/bin/env python # -*- coding: UTF-8 -*- # 项目二: # 1.要求:编写九九乘法表 # 2.分析: # 根据九九乘法表的样式 ...
- 用Python实现九九乘法表打印
#!usr/bin/env python # -*- coding:utf-8 -*- # dic={ # 'apple':10, # 'iphon':5000, # 'wwatch Tv':3000 ...
- 用python写九九乘法表
用python来写九九乘法表,九九乘法表的结构是这样子的: 第一行是1 * 1 = 1,第二行是1 * 2 = 2 | 2 * 2 = 4...以此类推.注意到没,每一行的第一个乘的数字在从1到当行变 ...
- 用python实现九九乘法表输出-两种方法
2019-08-05 思考过程:九九乘法表需要两层循环,暂且称之为内循环和外循环,因此需要写双层循环来实现. 循环有for和while两种方式. for循环的实现 for i in range(1,1 ...
- Flask python初期九九乘法表
from flask import Flask #导入 app = Flask(__name__) @app.route('/') def index(): res=" " ...
- Python 练习:九九乘法表
num = 1 while num <= 9: tmp = 1 while tmp <= num: print(tmp, "*", num, "=" ...
- python 之九九乘法表
for i in range(1,10): for j in range(1,i+1): print(f"{j}*{i}={i*j}",end='\t') print() 运行结果 ...
随机推荐
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- UIView 转 UIImage
这个方法很实用,特别是在做水印相机得时候... - (UIImage*) imageWithUIView:(UIView*) view{ // 创建一个bitmap的context // 并把它设置成 ...
- STS(Spring Tool Suite)建立默认的spring mvc项目
引入响应的jar包解决报错: 由于国内的网络限制,下载会较慢.使用之前可自行更换maven的镜像路径,越近越好.
- Hopscotch(细节)
Hopscotch Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit ...
- [Regular Expressions] Match the Same String Twice
Regular Expression Backreferences provide us a method to match a previously captured pattern a secon ...
- 男同胞爱小秘籍--作为爱他的女朋友了几天C规划
各位男同胞,不知道你的女朋友没有在过去的一问天,你这个问题~~ 场景重现: 女友:"今天天气不错." 你们:"对" 女友:"今天是我们知道它的最初几天 ...
- qt超强精美绘图控件 - QCustomPlot一览 及 安装使用教程
1.概述 QCustomPlot 是一个超强超小巧的qt绘图类,非常漂亮,非常易用,只需要加入一个qcustomplot.h和qcustomplot.cpp文件即可使用,远比qwt方便和漂亮,可以自己 ...
- 曾经很长时间不会写的两个SQL语句(group by,having)
1.统计各部门的平均工资,平均资金(要求同时显示出部门名称,部门编号,部门总人数) SQL)),) 部门平均工资,)),) 部门平均资金 FROM EMP E RIGHT JOIN DEPT D ON ...
- log4j参数说明
log4j.properties 使用 一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session ...
- java中的native关键字
参照下面的链接http://blog.163.com/yueyemaitian@126/blog/static/21475796200701491621267/