Python练习:九九乘法表
打印 n * n 的乘法表
#打印 9*9 乘法表
def Multiplication(n):
# n - 定义打印的行数
max_len = len(str((n)**2)) #计算最大值的占位(用于打印时输出更好看)
for row in range(1,n+1):
for col in range(1,row+1):
res = str(row * col)
print( '{0}'.format(res).rjust(max_len),end=" ") #打印一行
print("")#打印完一行后换行 #指定要打印的行数并输出
n = 9
Multiplication( n )
输出结果:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
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实现九九乘法表
1.用“#”组成的矩形的实现 代码 eight = int(input("Height:")) #用户输入高度 width = int(input("Width:&quo ...
- 用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() 运行结果 ...
随机推荐
- gitolite服务器部署中的一些坑
1.秘钥登录问题可参考< 安装gitolite,并ssh公钥无密码登录>http://www.cnblogs.com/tr0217/p/4517952.html,该文中推荐了阮一峰的< ...
- eclipse中maven下载不了私服上面的第三方包问题
问题描述在nexus中上传了第三方jar包,在本地项目中添加了引用,但就是下载不下来. 转载文章 1. 打开windows -> preferences -> maven,勾选如图所示 2 ...
- 安装RabbitMQ编译erlang时,checking for c compiler default output file name... configure:error:C compiler cannot create executables See 'config.log' for more details.
checking for c compiler default output file name... configure:error:C compiler cannot create executa ...
- Java基础:JVM垃圾回收算法
众所周知,Java的垃圾回收是不需要程序员去手动操控的,而是由JVM去完成.本文介绍JVM进行垃圾回收的各种算法. 1. 如何确定某个对象是垃圾 1.1. 引用计数法 1.2. 可达性分析 2. 典型 ...
- invalid bound statement (not found)
invalid bound statement (not found) mybatis 错误: 一般是Mapepr.xml文件中文nameapce没有和mapper接口发生映射,导致mybatis绑定 ...
- 洛谷 P1041 错解
P1041 传染病控制 题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染 ...
- mac的terminal快捷键
mac终端terminal快捷键: Command + K 清屏 Command + T 新建标签 Command +W 关闭当前标签页 Command + S 保存终端输出 Command + ...
- Vlan ---虚拟局域网
VLAN是一种将局域网(LAN)设备从逻辑上划分(注意,不是从物理上划分)成一个个网段(或者说是更小的局域网LAN),从而实现虚拟工作组(单元)的数据交换技术.VLAN(Virtual Local A ...
- linux下activemq安装与配置
一.下载:apache-activemq-5.14.0-bin.tar.gz http://activemq.apache.org/activemq-5140-release.html 二.安装a ...
- MIT KIT OpenID Connect Demo Client
Hello world! You are NOT currently logged in. This example application is configured with several pa ...