- 博客(13)
- 资源 (2)
- 问答 (2)
- 收藏
- 关注
原创 python 随机抢红包
"""发红包时用户输入一个红包总金额和待发红包总数,发布红包后,其它用户抢红包时可以随机得到不定金额的红包(前 n 个人中每个人都能抢到红包),RP 好的可能抢到几块,RP 不好时可能只会抢到几 毛,甚至几分钱二倍均值法方法实现的原理是:每次以 [最小值,红包剩余金额 / 人数 * 2] 的区间进行取值。假设红包金额为 88.88,红包数量为 8 个,理想情况下,方法的实现效果:第一个人领取红包金额区间为 [0.01, 88.88 / 8 * 2],即是 [0.01, 22.22] 之间
2021-11-01 16:54:23
857
原创 不使用循环和模块,读取字符串出现次数最多的一个字符
a = "aaaabbccccc"b = list(set(a)) # 将字符串a转换为列表,并去重print(b)c = set( map(lambda x:(x, a.count(x)), b )) # 读取b中的字符在a中出现的次数print(c)dic = dict(c) # 将c转换为字典格式print(dic)print('第一种:',list(dic.keys())[list(dic.values()).index(max(dic.values()..
2021-09-22 11:07:58
168
原创 python 数学运算符,数学函数及使用
1.运算符符号描述示例结果+加法,亦可重载为连接符1+2','a'+'b'3,ab-减法3-12*乘法3*26**乘方3**327/除法27/55.4//除法取整27//73%除法取余27%76==恒等于,比较对象是否相等'a'=='b'False!=不等于,比较两个对象是否不相等'a'!='b'True>大于,返回x是否大于y3>2True<
2021-07-20 18:03:05
607
原创 python 正则表达式
import rec = "[22,33.3]:33@4,5h"b= re.findall('(-?\d+(?:\.\d+)?)',c)print(b)输出结果:
2021-07-15 14:48:49
546
原创 python 多行输入;将多行字符串,按行装入列表,并去重
a = '''浙M55555浙A11111浙A44443浙M55555浙A11111浙M55555浙A56688沪牌3E3333浙A11111浙M55555浙M55555浙A11111浙Y66666'''print(a.replace('\n' , ',')) # 换行符由 “,”替换b = a.replace('\n' , ',').strip(',').split(',') # 将替换后的字符串,将“,”分隔的字符串转为列表print(b)print(li
2021-06-18 10:43:51
4187
原创 python 获取某路径下的文件名,并将.doc文件转为.docx文件,并保存到同级目录新建的文件下
# coding:utf-8import osimport shutilfrom win32com import client# 创建新文件夹def create_folder(old_path): try: print('old_path:'+ old_path) folder = old_path.rsplit('\\')[-1] + '-new' # 新文件夹的名称 : 原路径最后的文件夹名+-new print('fold
2021-05-20 17:28:27
281
原创 python 读取txt文件,并保存到excel文件中
import linecacheimport openpyxlfilename = r"需要打开的.txt文件"myfile = open(filename)lines = len(myfile.readlines())workbook = openpyxl.Workbook()sheet = workbook.activefor i in range(lines): text=linecache.getline(filename,i+1) print(i+1,text)
2021-04-29 14:27:34
2224
原创 python 身份证号校验码计算方法
# 身份证验证规则:# 第十八位数字(校验码)的计算方法为:# 1.将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2# 2.将这17位数字和系数相乘的结果相加与11进行相除。# 3.余数0 1 2 3 4 5 6 7 8 9 10这11个数字,其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2。# 4.例如 余数为 0 , 则身份证最后一位就是1# 余数为 2
2021-04-02 10:47:46
2271
原创 pyqt5 自定义倒计时界面
# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'QmainWindow1.ui'## Created by: PyQt5 UI code generator 5.14.2## WARNING! All changes made in this file will be lost!import sysimport timefrom PyQt5 import QtCore, QtGui,
2021-01-28 17:10:08
1116
原创 python 点击按钮,弹出提示框,2s后自动关闭提示框
# # -*- encoding: utf-8 -*-#import sysfrom PyQt5.QtWidgets import QPushButton, QApplication,QDesktopWidgetfrom PyQt5.QtWidgets import QWidgetfrom PyQt5 import QtCore, QtGui, QtWidgets, Qtimport timecurrentTime = time.strftime("%H:%M %p") # 当前时间(时
2020-12-22 13:40:29
2708
2
原创 python中时间日期格式化符号
import time# python中时间日期格式化符号:print(time.strftime("两位数的年份表示(00-99):%y")) # %y 两位数的年份表示(00-99)print(time.strftime("四位数的年份表示(000-9999):%Y")) # %Y 四位数的年份表示(000-9999)print(time.strftime("月份(01-12):%m")) # %m 月份(01-12)print(time.strft
2020-12-22 13:06:55
869
原创 python3.8 修改/增加json文件中的中文字段
python3.8 修改/增加json文件中的中文字段# encoding: utf-8import json# 读取配置def read_config(): with open("jsonfile/file.json") as json_file: # json_file = open("jsonfile/file.json","r", encoding='utf-8') config = json.load(json_file,encoding='gbk')
2020-12-20 14:55:32
822
2
如何使用python取消word文件中的所有超链接
2021-10-28
使用python,编写API,通过接口打开.docx文件,添加批注后保存文件
2021-08-27
TA创建的收藏夹 TA关注的收藏夹
TA关注的人