上传文件至 'Other'
This commit is contained in:
parent
f6ad89118c
commit
ecc9612b82
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,117 @@
|
|||
# psutil 模块
|
||||
|
||||
```shell
|
||||
#psutil.cpu_times(percpu=False) #查看CPU所有信息
|
||||
scputimes(user=306.98, nice=2.01, system=337.34, idle=410414.39, iowait=78.37, irq=0.0, softirq=17.42, steal=0.0, guest=0.0, guest_nice=0.0)
|
||||
|
||||
#user:用户进程花费的时间
|
||||
#nice:用户模式执行Niced优先级进程花费的时间
|
||||
#system:内核模式进程花费的时间
|
||||
#idle:闲置时间
|
||||
#iowait:等待I/O完成的时间
|
||||
#irq:处理硬件中断的时间
|
||||
#softirq:处理软件中断的时间
|
||||
#steal:虚拟化环境中运行的其他操作系统花费的时间
|
||||
#guest:在linux内核的控制下为客户端操作系统运行虚拟CPU所花费的时间
|
||||
#guest_nice:虚拟机运行niced所花费的时间
|
||||
```
|
||||
|
||||
```shell
|
||||
#psutil.cpu_count(logical=True) #显示cpu逻辑个数
|
||||
#psutil.cpu_count(logical=False) #显示CPU物理个数
|
||||
```
|
||||
|
||||
```python
|
||||
#psutil.cpu_stats() #CPU统计信息
|
||||
scpustats(ctx_switches=9838934, interrupts=10572621, soft_interrupts=5582125, syscalls=0)
|
||||
|
||||
#ctx_switches:启动后的上下问切换次数
|
||||
#interrupts:自启动以来的中断次数
|
||||
#soft_interrupts:启动后的软件中断数量
|
||||
#syscalls:启动以来的系统调用次数,linux为0
|
||||
```
|
||||
|
||||
```python
|
||||
#mem = psutil.virtual_memory() #获取内存完整信息
|
||||
svmem(total=2078892032, available=1508818944, percent=27.4, used=367063040, free=135192576, active=874614784, inactive=694231040, buffers=122880, cached=1576513536, shared=10444800, slab=255148032)
|
||||
|
||||
#total:总物理内存
|
||||
#available:可用的内存
|
||||
#used:使用的内存
|
||||
#free:完全没有使用的内存
|
||||
#active:当前正在使用的内存
|
||||
#inactive:标记为未使用的内存
|
||||
#buffers:缓存文件系统元数据使用的内存
|
||||
#cached:缓存各种文件的内存
|
||||
#shared:可以被多个进程同时访问的内存
|
||||
#slab:内核数据结构缓存的内存
|
||||
|
||||
#psutil.swap_memory() #获取swap内存信息
|
||||
sswap(total=2148528128, used=270336, free=2148257792, percent=0.0, sin=0, sout=12288)
|
||||
|
||||
#total:以字节为单位的总交换内存
|
||||
#used:以字节为单位使用交换内存
|
||||
#free:以字节为单位的可用交换内存
|
||||
#percent:使用百分比
|
||||
#sin:系统从磁盘交换的字节数
|
||||
#sout:系统从磁盘换出的字节数
|
||||
```
|
||||
|
||||
```python
|
||||
#psutil.disk_partitions(all=False) #获取磁盘完整信息
|
||||
[sdiskpart(device='/dev/sda3', mountpoint='/', fstype='xfs', opts='rw,seclabel,relatime,attr2,inode64,noquota'),
|
||||
sdiskpart(device='/dev/sda5', mountpoint='/home', fstype='xfs', opts='rw,seclabel,relatime,attr2,inode64,noquota'),
|
||||
sdiskpart(device='/dev/sda1', mountpoint='/boot', fstype='xfs', opts='rw,seclabel,relatime,attr2,inode64,noquota')]
|
||||
|
||||
# device 设备名称
|
||||
# mountpoint 挂载目录
|
||||
# fstype 文件系统类型
|
||||
# opts 挂载方式
|
||||
```
|
||||
|
||||
```shell
|
||||
#psutil.disk_usage('/') #获取分区使用情况
|
||||
sdiskusage(total=53660876800, used=3662462976, free=49998413824, percent=6.8)
|
||||
|
||||
#total:总的大小(字节)
|
||||
#used:已使用的大小(字节)
|
||||
#free:空闲的大小(字节)
|
||||
#percent:使用百分比
|
||||
```
|
||||
|
||||
```python
|
||||
#psutil.disk_io_counters(perdisk=False,nowrap=True) #将系统范围的磁盘I/0统计作为命名元组返回 如果perdisk为True 区分单个分区
|
||||
sdiskio(read_count=20173, write_count=196206, read_bytes=777824768, write_bytes=2732865536, read_time=207425, write_time=363200, read_merged_count=57, write_merged_count=6063, busy_time=277196)
|
||||
|
||||
#read_count:读取次数
|
||||
#write_count:写入次数
|
||||
#read_bytes:读取的字节数
|
||||
#write_bytes:写入的字节数
|
||||
#read_time:从磁盘读取的时间(以毫秒为单位)
|
||||
#write_time:写入磁盘的时间(毫秒为单位)
|
||||
#busy_time:花费在实际I/O上的时间
|
||||
#read_merged_count:合并读取的数量
|
||||
#write_merged_count:合并写入次数
|
||||
```
|
||||
|
||||
```python
|
||||
In [6]: import psutil,time
|
||||
In [7]: psutil.boot_time() #系统启动时间戳
|
||||
Out[7]: 1567342872.0
|
||||
In [9]: time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(psutil.boot_time()))
|
||||
Out[9]: '2019-09-01 21:01:12'
|
||||
```
|
||||
|
||||
```python
|
||||
In [10]: psutil.users() # 查看当前连接的用户
|
||||
Out[10]:
|
||||
[suser(name='root', terminal='tty1', host='', started=1567070080.0, pid=6547),
|
||||
suser(name='root', terminal='pts/0', host='192.168.252.1', started=1567433088.0, pid=82270),
|
||||
suser(name='root', terminal='pts/1', host='192.168.252.1', started=1567433088.0, pid=82287),
|
||||
suser(name='root', terminal='pts/2', host='192.168.252.1', started=1567436416.0, pid=11672),
|
||||
suser(name='root', terminal='pts/3', host='192.168.252.1', started=1567436416.0, pid=11673),
|
||||
suser(name='root', terminal='pts/4', host='192.168.252.1', started=1567436416.0, pid=16554),
|
||||
suser(name='root', terminal='pts/5', host='192.168.252.1', started=1567436416.0, pid=16559)]
|
||||
|
||||
```
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
# python --pyecharts
|
||||
|
||||
- echart 是一个制表制图的模块
|
||||
- pyecharts python中的echart接口模块
|
||||
|
||||
```python
|
||||
pip3 install pyecharts==0.1.9.4
|
||||
```
|
||||
|
||||
全球国家地图: [echarts-countries-pypkg](https://github.com/pyecharts/echarts-countries-pypkg) (1.9MB): 世界地图和 213 个国家,包括中国地图
|
||||
中国省级地图: [echarts-china-provinces-pypkg](https://github.com/pyecharts/echarts-china-provinces-pypkg) (730KB):23 个省,5 个自治区
|
||||
中国市级地图: [echarts-china-cities-pypkg](https://github.com/pyecharts/echarts-china-cities-pypkg) (3.8MB):370 个中国城市
|
||||
|
||||
```python
|
||||
# 柱形图
|
||||
from pyecharts import Line, Bar, Pie, EffectScatter
|
||||
bar =Bar("我的第一个图表", "这里是副标题")
|
||||
bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90])
|
||||
bar.show_config()
|
||||
bar.render()
|
||||
# 普通折线图
|
||||
line = Line('折线图')
|
||||
line.add('商家A', attr, v1, mark_point=['max'])
|
||||
line.add('商家B', attr, v2, mark_point=['min'], is_smooth=True)
|
||||
line.show_config()
|
||||
line.render(path='./data/01-04折线图.html')
|
||||
|
||||
# 阶梯折线图
|
||||
line2 = Line('阶梯折线图')
|
||||
line2.add('商家A', attr, v1, is_step=True, is_label_show=True)
|
||||
line2.show_config()
|
||||
line2.render(path='./data/01-05阶梯折线图.html')
|
||||
|
||||
# 面积折线图
|
||||
line3 =Line("面积折线图")
|
||||
line3.add("商家A", attr, v1, is_fill=True, line_opacity=0.2, area_opacity=0.4, symbol=None, mark_point=['max'])
|
||||
line3.add("商家B", attr, v2, is_fill=True, area_color='#a3aed5', area_opacity=0.3, is_smooth=True)
|
||||
line3.show_config()
|
||||
line3.render(path='./data/01-06面积折线图.html')
|
||||
|
||||
# 柱形图-折线图
|
||||
from pyecharts import Bar, Line, Overlap
|
||||
|
||||
att = ['A', 'B', 'C', 'D', 'E', 'F']
|
||||
v3 = [10, 20, 30, 40, 50, 60]
|
||||
v4 = [38, 28, 58, 48, 78, 68]
|
||||
|
||||
bar = Bar("柱形图-折线图")
|
||||
bar.add('bar', att, v3)
|
||||
line = Line()
|
||||
line.add('line', att, v4)
|
||||
|
||||
overlap = Overlap()
|
||||
overlap.add(bar)
|
||||
overlap.add(line)
|
||||
overlap.show_config()
|
||||
overlap.render(path='./data/01-066柱形图-折线图.html')
|
||||
# 饼图
|
||||
pie = Pie('饼图')
|
||||
pie.add('芝麻饼', attr, v1, is_label_show=True)
|
||||
pie.show_config()
|
||||
pie.render(path='./data/01-07饼图.html')
|
||||
|
||||
# 玫瑰饼图
|
||||
pie2 = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
|
||||
pie2.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
|
||||
pie2.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True)
|
||||
pie2.show_config()
|
||||
pie2.render(path='./data/01-08玫瑰饼图.html')
|
||||
```
|
||||
|
||||
```python
|
||||
# 中国地图
|
||||
from pyecharts import Map
|
||||
value = [155, 10, 66, 78]
|
||||
attr = ["福建", "山东", "北京", "上海"]
|
||||
map = Map("全国地图示例", width=1200, height=600)
|
||||
map.add("", attr, value, maptype='china')
|
||||
map.render()
|
||||
```
|
||||
|
||||
```python
|
||||
# 词云
|
||||
from pyecharts import WordCloud
|
||||
|
||||
name =['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp', 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham', 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
|
||||
value =[10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
|
||||
wordcloud =WordCloud(width=1300, height=620)
|
||||
wordcloud.add("", name, value, word_size_range=[20, 100])
|
||||
wordcloud.show_config()
|
||||
wordcloud.render(path='05-01权重词云.html')
|
||||
|
||||
wordcloud2 =WordCloud(width=1300, height=620)
|
||||
wordcloud2.add("", name, value, word_size_range=[30, 100], shape='diamond')
|
||||
wordcloud2.show_config()
|
||||
wordcloud2.render(path='05-02变形词云.html')
|
||||
```
|
||||
|
||||
```python
|
||||
from pyecharts import Map,Geo
|
||||
value = [95.1, 23.2, 43.3, 66.4, 88.5]
|
||||
attr= ["China", "Canada", "Brazil", "Russia", "United States"]
|
||||
|
||||
# 省和直辖市
|
||||
province_distribution = {'河南': 45.23, '北京': 37.56, '河北': 21, '辽宁': 12, '江西': 6, '上海': 20, '安徽': 10, '江苏': 16, '湖南': 9, '浙江': 13, '海南': 2, '广东': 22, '湖北': 8, '黑龙江': 11, '澳门': 1, '陕西': 11, '四川': 7, '内蒙古': 3, '重庆': 3, '云南': 6, '贵州': 2, '吉林': 3, '山西': 12, '山东': 11, '福建': 4, '青海': 1, '舵主科技,质量保证': 1, '天津': 1, '其他': 1}
|
||||
provice=list(province_distribution.keys())
|
||||
values=list(province_distribution.values())
|
||||
|
||||
# 城市 -- 指定省的城市 xx市
|
||||
city = ['郑州市', '安阳市', '洛阳市', '濮阳市', '南阳市', '开封市', '商丘市', '信阳市', '新乡市']
|
||||
values2 = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1]
|
||||
|
||||
# 区县 -- 具体城市内的区县 xx县
|
||||
quxian = ['夏邑县', '民权县', '梁园区', '睢阳区', '柘城县', '宁陵县']
|
||||
values3 = [3, 5, 7, 8, 2, 4]
|
||||
|
||||
|
||||
map0 = Map("世界地图示例", width=1200, height=600)
|
||||
map0.add("世界地图", attr, value, maptype="world", is_visualmap=True, visual_text_color='#000')
|
||||
map0.render(path="04-00世界地图.html")
|
||||
```
|
||||
|
||||
```python
|
||||
# 热力分布图
|
||||
from pyecharts import Geo
|
||||
data = [
|
||||
("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15),
|
||||
("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21),
|
||||
("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25)]
|
||||
|
||||
geo = Geo("全国主要城市空气质量热力图", "data from pm2.5", title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59')
|
||||
attr, value = geo.cast(data)
|
||||
geo.add("空气质量热力图", attr, value, visual_range=[0, 25], type='heatmap',visual_text_color="#fff", symbol_size=15, is_visualmap=True, is_roam=False)
|
||||
geo.show_config()
|
||||
geo.render(path="b.html")
|
||||
```
|
||||
|
||||
```python
|
||||
# 空气质量评分
|
||||
indexs = ['上海', '北京', '合肥', '哈尔滨', '广州', '成都', '无锡', '杭州', '武汉', '深圳', '西安', '郑州', '重庆', '长沙']
|
||||
values = [4.07, 1.85, 4.38, 2.21, 3.53, 4.37, 1.38, 4.29, 4.1, 1.31, 3.92, 4.47, 2.40, 3.60]
|
||||
|
||||
geo = Geo("全国主要城市空气质量评分", "data from pm2.5", title_color="#fff", title_pos="center", width=1200, height=600, background_color='#404a59')
|
||||
|
||||
# type="effectScatter", is_random=True, effect_scale=5 使点具有发散性
|
||||
geo.add("空气质量评分", indexs, values, type="effectScatter", is_random=True, effect_scale=5, visual_range=[0, 5],visual_text_color="#fff", symbol_size=15, is_visualmap=True, is_roam=False)
|
||||
geo.show_config()
|
||||
geo.render(path="04-05空气质量评分.html")
|
||||
```
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
# python3 日志信息
|
||||
|
||||
### 日志模块 logging
|
||||
|
||||
- 日志级别
|
||||
|
||||
```python
|
||||
import logging
|
||||
# 5个级别,从上到下
|
||||
logging.debug('调试模式')
|
||||
logging.info('详细信息')
|
||||
logging.warning('警告信息')
|
||||
logging.error('错误信息')
|
||||
logging.critical('严重错误')
|
||||
```
|
||||
|
||||
- 配置日志文件
|
||||
|
||||
```python
|
||||
import logging
|
||||
logging.basicConfig(filename='access.log',level=logging.DEBUG,format='%(asctime)s %(message)s',datefmt='%Y-%m-%d %H:%M:%S')
|
||||
#basicConfig 方法对日志进本信息进行配置,文件名、日志级别、输出格式等,但必须以key-value形式使用
|
||||
logging.debug('调试模式') # 上方设置中为debug,所以会打印所有信息,默认不低于设置级别
|
||||
logging.info('详细信息')
|
||||
logging.warning('警告信息')
|
||||
```
|
||||
|
||||
- format自定义格式
|
||||
|
||||
```python
|
||||
%(levelno)s 数字形式的日志级别
|
||||
%(levelname)s 文本形式的日志级别
|
||||
%(pathname)s 调用日志输出函数的模块的完整路径名,可能没有
|
||||
%(filename)s 调用日志输出函数的模块的文件名
|
||||
%(module)s 调用日志输出函数的模块名
|
||||
%(funcName)s 调用日志输出函数的函数名
|
||||
%(lineno)d 调用日志输出函数的语句所在的代码行
|
||||
%(created)f 当前时间,用UNIX标准的表示时间的浮 点数表示
|
||||
%(relativeCreated)d 输出日志信息时的,自Logger创建以 来的毫秒数
|
||||
%(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
|
||||
%(thread)d 线程ID。可能没有
|
||||
%(threadName)s 线程名。可能没有
|
||||
%(process)d 进程ID。可能没有
|
||||
%(message)s 用户输出的消息
|
||||
```
|
||||
|
||||
- ## 日志与控制台同时输出
|
||||
|
||||
**Python 使用logging模块记录日志涉及四个主要类,使用官方文档中的概括最为合适:**
|
||||
|
||||
- logger提供了应用程序可以直接使用的接口;
|
||||
- handler将(logger创建的)日志记录发送到合适的目的输出;
|
||||
- filter提供了细度设备来决定输出哪条日志记录;
|
||||
- formatter决定日志记录的最终输出格式
|
||||
|
||||
### 一个同时输出到屏幕、文件的完成例子
|
||||
|
||||
可按以下步骤进行创建
|
||||
|
||||
1. 生成logger对象
|
||||
2. 生成handler 对象
|
||||
3. 把handler 对象绑定到logger对象
|
||||
4. 生成formatter 对象
|
||||
5. 将formatter对象绑定到handler对象
|
||||
|
||||
```python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def logger(log_obj):
|
||||
|
||||
logger = logging.getLogger(log_obj)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
console_handle = logging.StreamHandler()
|
||||
|
||||
log_file = "access.log"
|
||||
file_handle = logging.FileHandler(log_file)
|
||||
file_handle.setLevel(logging.WARNING)
|
||||
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
console_handle.setFormatter(formatter)
|
||||
file_handle.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(console_handle)
|
||||
logger.addHandler(file_handle)
|
||||
|
||||
return logger
|
||||
```
|
||||
|
||||
### 日志文件截取
|
||||
|
||||
- 按照大小截取
|
||||
logging.handlers.RotatingFileHandler()
|
||||
当文件达到一定大小之后,它会自动将当前日志文件改名,然后创建 一个新的同名日志文件继续输出。比如日志文件是chat.log。当chat.log达到指定的大小之后,RotatingFileHandler自动把 文件改名为chat.log.1。不过,如果chat.log.1已经存在,会先把chat.log.1重命名为chat.log.2。。。最后重新创建 chat.log,继续输出日志信息。它的函数是:
|
||||
|
||||
RotatingFileHandler( filename[, mode[, maxBytes[, backupCount]]])
|
||||
其中filename和mode两个参数和FileHandler一样。
|
||||
|
||||
maxBytes用于指定日志文件的最大文件大小。如果maxBytes为0,意味着日志文件可以无限大,这时上面描述的重命名过程就不会发生。
|
||||
|
||||
backupCount用于指定保留的备份文件的个数。比如,如果指定为2,当上面描述的重命名过程发生时,原有的chat.log.2并不会被更名,而是被删除。
|
||||
|
||||
- 按照时间截取
|
||||
logging.handlers.TimedRotatingFileHandler()
|
||||
这个Handler和RotatingFileHandler类似,不过,它没有通过判断文件大小来决定何时重新创建日志文件,而是间隔一定时间就 自动创建新的日志文件。重命名的过程与RotatingFileHandler类似,不过新的文件不是附加数字,而是当前时间。它的函数是:
|
||||
|
||||
TimedRotatingFileHandler( filename [,when [,interval [,backupCount]]])
|
||||
其中filename参数和backupCount参数和RotatingFileHandler具有相同的意义。
|
||||
|
||||
interval是时间间隔。
|
||||
|
||||
when参数是一个字符串。表示时间间隔的单位,不区分大小写。它有以下取值:
|
||||
|
||||
S 秒
|
||||
M 分
|
||||
H 小时
|
||||
D 天
|
||||
W 每星期(interval==0时代表星期一)
|
||||
midnight 每天凌晨
|
||||
|
||||
- 代码实现如下:
|
||||
|
||||
```
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import logging
|
||||
from logging import handlers
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
log_file_size = "sizelog.log"
|
||||
log_file_time = "timelog.log"
|
||||
file_handler_size = logging.handlers.RotatingFileHandler(filename=log_file_size,maxBytes=10,backupCount=3)
|
||||
|
||||
file_handler_time = logging.handlers.TimedRotatingFileHandler(filename=log_file_time,when="S",interval=5,backupCount=3)
|
||||
|
||||
|
||||
formatter = logging.Formatter('%(asctime)s %(module)s:%(lineno)d %(message)s')
|
||||
|
||||
file_handler_size.setFormatter(formatter)
|
||||
file_handler_time.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(file_handler_size)
|
||||
logger.addHandler(file_handler_time)
|
||||
|
||||
logger.warning("test1")
|
||||
logger.warning("test12")
|
||||
logger.warning("test13")
|
||||
```
|
|
@ -0,0 +1,71 @@
|
|||
# python3 简单的算法题
|
||||
|
||||
### 求出1+2+3+..+100的和
|
||||
|
||||
```python
|
||||
print("计算1+2+3+...+100的结果:")
|
||||
result=0
|
||||
for i in range(101):
|
||||
result+=i
|
||||
print(result)
|
||||
```
|
||||
|
||||
### 求出1-2+3-4+..+99 的结果
|
||||
|
||||
```python
|
||||
num = 0
|
||||
for i in range(100):
|
||||
if i % 2 == 1:
|
||||
num +=i
|
||||
else:
|
||||
num -+i
|
||||
print(num)
|
||||
```
|
||||
|
||||
### 求输入的三个数如何由大到小输出
|
||||
|
||||
```python
|
||||
num = input('请输入数字\n')
|
||||
num = num.split()
|
||||
a,b,c = num
|
||||
a,b,c = int(a),int(b),int(c)
|
||||
if a > b : a,b = b,a
|
||||
if a > c : a,c = c,a
|
||||
if b > c : b,c = c,b
|
||||
print("输出结果 : %d %d %d" %(a,b,c)) # 也可以使用sort方法进行排序
|
||||
|
||||
s = [input(),input(),input()]
|
||||
s.sort()
|
||||
print "输出结果: %s" %s
|
||||
```
|
||||
|
||||
### 输出99乘法口诀表
|
||||
|
||||
```python
|
||||
for i in range(1,10):
|
||||
for j in range(1,10):
|
||||
print("%d*%d = %-3d" %(i,j,i*j),end="")
|
||||
print()
|
||||
|
||||
# 另一种方法
|
||||
c = 0
|
||||
while c < 9:
|
||||
c +=1
|
||||
a = 0
|
||||
while a < c:
|
||||
a += 1
|
||||
print('{} x {} = {}'.format(c,a,a*c),end=" ")
|
||||
print()
|
||||
```
|
||||
|
||||
### 输入n个数字,排列出有这n个数字组成的不同n位数
|
||||
|
||||
```python
|
||||
s = (1, 2, 3, 4)
|
||||
for a in s:
|
||||
for b in s:
|
||||
for c in s:
|
||||
if a != b and b != c and c != a:
|
||||
print("%d%d%d" % (a, b, c))
|
||||
```
|
||||
|
Loading…
Reference in New Issue