
Python
博客冲浪
knowledge is power
展开
-
使用Python进行Web页面元素提取
#gethtmllines() extractimageurls() showresults() saveresults()def main(): inputfile='nationalgeograhic.html' outputfile='nationalgeographic.txt' htmllines=gethtmllines(inputfile) imageurls=extractimageurls(htmllines) showresults(ima.原创 2021-08-25 19:41:55 · 567 阅读 · 0 评论 -
利用Python的jieba和wordcloud第三方库制作精美词云
import jiebaf=open('红楼梦.txt','r')txt=f.read()f.close()words=jieba.icut(txt)counts={}for word in words: if len(word)==1: continue else: counts[word]=counts.get(word,0)+1items=list(counts.items())items.sort(key=lambda x:x[1],.原创 2021-08-25 10:25:38 · 573 阅读 · 0 评论 -
Python的turtle和random标准库绘制雪景图做壁纸
from turtle import *from random import *def drawsnow(): hideturtle() pensize(2) for i in range(100): r,g,b=random(),random(),random() pencolor(r,g,b) penup() setx(randint(-350,350)) sety(randint(1,270).原创 2021-08-22 09:49:44 · 465 阅读 · 0 评论 -
利用Python的time库函数实现程序计时功能
import timedef coreLoop(): limit=10**8 while (limit>0): limit-=1def otherLoop1(): time.sleep(0.2)def otherLoop2(): time.sleep(0.4)def main(): starttime=time.localtime() print('程序开始时间:',time.strftime('%Y-%m-%d-%H:%M:%.原创 2021-08-21 18:09:45 · 858 阅读 · 0 评论 -
利用Python的标准库turtle库绘制图形入门实例
import turtleturtle.speed(2)turtle.setup(800,800,startx=None,starty=None)turtle.pensize(3)turtle.pu() #三角形turtle.goto(-200,-50)turtle.pd()turtle.begin_fill()turtle.color('red')turtle.circle(40,steps=3)turtle.end_fill()turtle.up()#四边形turtle.got.原创 2021-08-21 13:43:14 · 417 阅读 · 0 评论 -
利用Python对体育竞技比赛进行分析
程序设计:#MatchAnalysis.pyfrom random import randomdef printintro(): print('这个程序模拟两个选手A和B的某种竞技比赛') print('程序运行需要A和B的能力值(以0到1之间的小数表示)')def getinput(): a=eval(input('请输入选手A的能力值(0-1):')) b=eval(input('请输入选手B的能力值(0-1):')) n=eval(input(.原创 2021-08-19 10:37:10 · 1292 阅读 · 0 评论