![](https://img-blog.csdnimg.cn/20190918140145169.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Python_Practise
Python_Practise
Z0o1010
这个作者很懒,什么都没留下…
展开
-
一行代码画爱心
print('\n'.join([''.join([('Love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)]))效果如下:原创 2021-01-13 12:16:28 · 273 阅读 · 0 评论 -
随机位置出现自定义弹窗
import tkinter as tkimport randomimport threadingimport timedef test(): window = tk.Tk() width = window.winfo_screenwidth() height = window.winfo_screenheight() a = random.randrange(0, width) b = random.randrange(0, height) wi原创 2021-01-12 11:42:26 · 1405 阅读 · 2 评论 -
使用matplotlib绘制饼图
import matplotlib.pyplot as pltall = 400 + 200 + 100 + 50 + 100 + 60 + 60pieLabels = ['milk', 'water', 'vegetable', 'meat', 'fruit', 'eggs', 'others']baifenbi = [400/all, 200/all, 100/all, 50/all, 100/all, 60/all, 60/all]plt.pie(baifenbi, labels=pieL原创 2020-12-24 11:57:29 · 128 阅读 · 0 评论 -
使用matplotlib绘制散点图
import matplotlib.pyplot as pltx = [1, 2, 1, 4, 2, 5, 0, 0]y = [1, 4, 0, 0, 0, 2, 2, 12]plt.figure()plt.scatter(x, y)plt.xlabel("chidaozaotui(ci/yue)")plt.ylabel("qingjia(xiaoshi/yue)")plt.annotate("zhang3", xy=(x[0], y[0]))plt.annotate("li4", xy原创 2020-12-24 11:44:29 · 135 阅读 · 0 评论 -
计算n阶乘中尾部零的个数
def cal(n): x = 0 while n: x = x + n // 5 n = n // 5 return x原创 2020-11-27 10:19:48 · 164 阅读 · 0 评论 -
批量产生word文档且添加文字及图片,获取excel指定区域的值,
import randomimport xlrdfrom docx import Documentfrom docx.shared import Pt, Cmdoc = Document()# 输入excel路径data = xlrd.open_workbook(r"")table = data.sheets()[0]tables = []for rown in range(table.nrows): name = table.cell_value(rown, 1)原创 2020-11-23 14:31:11 · 106 阅读 · 0 评论 -
协程(异步)初了解及四种使用方法
# 1、greenlet 实现协程# from greenlet import greenlet### def fun1():# print(1)# gr2.switch()# print(2)# gr2.switch()### def fun2():# print(3)# gr1.switch()# print(4)# gr1.switch()### gr1 = greenlet(fun1)# gr2 =原创 2020-11-02 20:20:16 · 334 阅读 · 0 评论 -
线程池初了解
import timefrom multiprocessing.dummy import Poolstart_time = time.time()def get_page(str): print("正在下载:", str) time.sleep(2) print("下载成功:", str)name_list = ["A", "B", "C"]# 实例化一个线程池对象pool = Pool(4)# 将列表中每一个列表元素传递给 get_page 进行处理po原创 2020-10-29 21:43:42 · 56 阅读 · 0 评论 -
uvloop 初了解
import asyncioimport uvloopasyncio.set_event_loop_policy(uvlooop.EventLoopPolicy())# 编写 asyncio 代码,与之前写法一致# 内部事件循环会自动变为 uvloopasyncio.run()# 注意:一个 asgi -> uvicorn 内部使用的就是 uvloop...原创 2020-11-05 18:15:00 · 136 阅读 · 0 评论 -
将字符串第一个与最后一个字符进行互换/将字符串进行倒序排列
将字符串第一个与最后一个字符进行互换def front_back(str): if len(str) <= 1: return str return str[len(str) - 1] + str[1: len(str) - 1] + str[0]将字符串进行倒序排列def front_back(str): return list(reversed(str))...原创 2020-10-30 11:52:42 · 1457 阅读 · 0 评论 -
利用 docx 批量生成空白 Word 文档
import docxdoc = docx.Document()x = 100 for i in range(27): x += 1 doc.save(f"C:\\Users\\zhang\\Desktop\\{x}.docx")原创 2020-10-19 09:44:00 · 171 阅读 · 0 评论 -
将列表转换为字符串
a = ["a", "b", "c"]b = [str(i) for i in a]c = ','.join(b)print(c)原创 2020-10-19 09:42:25 · 393 阅读 · 0 评论 -
计算器
import tkinter as tkclass Calc(tk.Tk): """计算器窗体类""" def __init__(self): """初始化实例""" tk.Tk.__init__(self) self.title("计算器") self.memory = 0 # 暂存数值 self.create() def create(self): """创建界面"""原创 2020-10-12 23:05:28 · 275 阅读 · 0 评论 -
random 随机获值小游戏
利用 random 随机函数进行随机获值,若值为 5,则胜利import randomroll = 0count = 0print("First person to roll a 5 wins!")while roll != 5: name = input("Enter a name, or 'q' to quit:") if name.strip() == "q": break elif name.strip() == "": con原创 2020-09-30 11:04:13 · 115 阅读 · 0 评论 -
无限弹窗
import osfor i in range(10): os.system("start cmd")原创 2020-09-25 09:31:50 · 276 阅读 · 0 评论 -
Calculate
class Count: def __init__(self): x = int(input("请输入第一个数字:")) y = input("请输入运算符") z = int(input("请输入第二个数字:")) if y == "+": print("计算结果为:{}".format(x + z)) print("") elif y == "-":原创 2020-09-15 20:38:29 · 348 阅读 · 0 评论 -
统计各个字符个数
# coding = utf-8def count(): value = input('请输入信息:') a = 0 b = 0 c = 0 d = 0 for i in value: if 47 < ord(i) < 58: c += 1 elif 64 < ord(i) < 91: a += 1 elif 96 < ord(i)原创 2020-09-15 20:36:35 · 95 阅读 · 0 评论 -
计算阿姆斯特朗数
# coding = utf-8# 1、用户输入任意一个整数值,计算该值至零之间的所有阿姆斯特朗数# 2、阿姆斯特朗数:一个整数其每一位数的次方(次方数为该数位数)的和值即为该整数本身origin = int(input("请您输入准备计算阿姆斯特朗数的非零区间极值:"))while origin != 0: current = origin if origin > 0 else abs(origin) length = 0 while current != 0:原创 2020-09-14 15:16:39 · 428 阅读 · 0 评论 -
计算BMI指数
# *********** coding=utf-8 ***********height = float(input("请输入您的身高(m):"))weight = float(input("请输入您的体重(kg):"))bmi = weight / (height * height)if bmi >= 29.9: print("您的BMI指数为:" + str(bmi)) print("肥胖 ︿@_@︿")else: if bmi >= 24.9:原创 2020-09-14 15:16:11 · 616 阅读 · 0 评论 -
猜拳
# coding = utf-8import randomi = 0while True: j = random.randint(0, 2) jInfo = "剪" if j == 0 else ("锤" if j == 1 else "包") k = random.randint(0, 2) kInfo = "剪" if k == 0 else ("锤" if k == 1 else "包") print("让我们" + ("" if i == 0 else原创 2020-09-14 15:15:34 · 306 阅读 · 0 评论 -
斗兽棋
# coding = utf-8import randomchess = '鼠猫狗狼豹虎狮象'print("*" * 45)print("斗兽棋规则:鼠 < 猫 < 狗 < 狼 < 豹 < 虎 < 狮 < 象")print("*" * 45)while True: print("这样,你出 『 {} 』 我出 『 {} 』 ,如何???".format(chess[random.randint(0, 7)], chess[random.rand原创 2020-09-14 15:14:58 · 681 阅读 · 0 评论 -
判断是否闰年
# coding=utf-8year = int(input("请输入您要判断是否闰年的年份信息:"))check = (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)print("公元 " + str(year) + (" 是" if check else " 不是") + "闰年!")currentTime = int(input("请输入此刻时间(整数型):"))print("半夜三更好" if 0 <= curr原创 2020-09-14 15:13:43 · 52 阅读 · 0 评论 -
打印图形
# coding = utf-8# 正方形height = int(input("请您输入要打印的正方形的边长:"))for _ in range(0, height): for _ in range(0, height): print("■ ", end='') print()triangleHeight = int(input("请输入您要打印的正直角三角形的行高(正整数):"))# 正直角三角形for i in range(0, triangleHeight原创 2020-09-14 15:11:35 · 145 阅读 · 0 评论 -
0-N之间所有数之和
# coding = utf-8rangeValue = int(input("请输入您要计算区间和值的最大数(整数型):"))sumValue = 0# while True:# if rangeValue == 0:# break# else:# if rangeValue < 0:# sumValue += rangeValue# rangeValue += 1#原创 2020-09-14 15:03:46 · 445 阅读 · 0 评论 -
0-N之间所有数平方和
# coding = utf-8value = int(input("请输入您欲进行数值运算的整数区间极值:"))sumValue = 0while value != 0: sumValue += value ** 2 print("value = " + str(value) + " sumValue = " + str(sumValue)) value = value - 1 if value > 0 else value + 1...原创 2020-09-14 15:01:08 · 269 阅读 · 0 评论