为提高大家对“Python”编程语言的学习兴趣,今天给大家分享几款有趣的Python程序代码,感兴趣的小伙伴可以跟着学习借鉴哦!当然进群:700341555可以获取Python学习资料哦!
分享一:"啥是佩奇?"让Python语言告诉你
用Python代码创作一副佩奇:
# coding:utf-8 import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255,155,192),"pink") t.setup(840,500) t.speed(10) #鼻子 t.pu() t.goto(-100,100) t.pd() t.seth(-30) t.begin_fill() a=0.4 for i in range(120): if 0<=i<30 or 60<=i<90: aa=a+0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: aa=a-0.08 t.lt(3) t.fd(a) t.end_fill() t.pu() t.seth(90) t.fd(25) t.seth(0) t.fd(10) t.pd() t.pencolor(255,155,192) t.seth(10) t.begin_fill() t.circle(5) t.color(160,82,45) t.end_fill() t.pu() t.seth(0) t.fd(20) t.pd() t.pencolor(255,155,192) t.seth(10) t.begin_fill() t.circle(5) t.color(160,82,45) t.end_fill() #头 t.color((255,155,192),"pink") t.pu() t.seth(90) t.fd(41) t.seth(0) t.fd(0) t.pd() t.begin_fill() t.seth(180) t.circle(300,-30) t.circle(100,-60) t.circle(80,-100) t.circle(150,-20) t.circle(60,-95) t.seth(161) t.circle(-300,15) t.pu() t.goto(-100,100) t.pd() t.seth(-30) a=0.4 for i in range(60): if 0<=i<30 or 60<=i<90: aa=a+0.08 t.lt(3) #向左转3度 t.fd(a) #向前走a的步长 else: aa=a-0.08 t.lt(3) t.fd(a) t.end_fill() #耳朵 t.color((255,155,192),"pink") t.pu() t.seth(90) t.fd(-7) t.seth(0) t.fd(70) t.pd() t.begin_fill() t.seth(100) t.circle(-50,50) t.circle(-10,120) t.circle(-50,54) t.end_fill() t.pu() t.seth(90) t.fd(-12) t.seth(0) t.fd(30) t.pd() t.begin_fill() t.seth(100) t.circle(-50,50) t.circle(-10,120) t.circle(-50,56) t.end_fill() #眼睛 t.color((255,155,192),"white") t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-95) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() t.color((255,155,192),"white") t.pu() t.seth(90) t.fd(-25) t.seth(0) t.fd(40) t.pd() t.begin_fill() t.circle(15) t.end_fill() t.color("black") t.pu() t.seth(90) t.fd(12) t.seth(0) t.fd(-3) t.pd() t.begin_fill() t.circle(3) t.end_fill() #腮 t.color((255,155,192)) t.pu() t.seth(90) t.fd(-95) t.seth(0) t.fd(65) t.pd() t.begin_fill() t.circle(30) t.end_fill() #嘴 t.color(239,69,19) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(-100) t.pd() t.seth(-80) t.circle(30,40) t.circle(40,80) #身体 t.color("red",(255,99,71)) t.pu() t.seth(90) t.fd(-20) t.seth(0) t.fd(-78) t.pd() t.begin_fill() t.seth(-130) t.circle(100,10) t.circle(300,30) t.seth(0) t.fd(230) t.seth(90) t.circle(300,30) t.circle(100,3) t.color((255,155,192),(255,100,100)) t.seth(-135) t.circle(-80,63) t.circle(-150,24) t.end_fill() #手 t.color((255,155,192)) t.pu() t.seth(90) t.fd(-40) t.seth(0) t.fd(-27) t.pd() t.seth(-160) t.circle(300,15) t.pu() t.seth(90) t.fd(15) t.seth(0) t.fd(0) t.pd() t.seth(-10) t.circle(-20,90) t.pu() t.seth(90) t.fd(30) t.seth(0) t.fd(237) t.pd() t.seth(-20) t.circle(-300,15) t.pu() t.seth(90) t.fd(20) t.seth(0) t.fd(0) t.pd() t.seth(-170) t.circle(20,90) #脚 t.pensize(10) t.color((240,128,128)) t.pu() t.seth(90) t.fd(-75) t.seth(0) t.fd(-180) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) t.pensize(10) t.color((240,128,128)) t.pu() t.seth(90) t.fd(40) t.seth(0) t.fd(90) t.pd() t.seth(-90) t.fd(40) t.seth(-180) t.color("black") t.pensize(15) t.fd(20) #尾巴 t.pensize(4) t.color((255,155,192)) t.pu() t.seth(90) t.fd(70) t.seth(0) t.fd(95) t.pd() t.seth(0) t.circle(70,20) t.circle(10,330) t.circle(70,30) t.done()
效果图如下:
分享二:一个可以套路别人的python小程序
程序是使用pycharm工具,python语言所写。程序包括客户端 client.py 和服务器端 server.py 两部分,利用了python中的socket包。
使用方法:
首先,你需要你和你的朋友在同一个局域网内,然后在你的主机上,运行服务器端 server.py。
然后,让你的朋友在他的电脑上运行客户端 client.py。
此时你朋友电脑的windows用户密码,就会变成一个随机密码,且这个生成的随机密码他本人无法得知,而是把这个密码通过socket传给了服务器端的你。
嗯,然后你朋友的电脑密码就只有你自己知道了~
上代码:
分享三:一段Python 恶搞代码
代码运行后windows将无限锁屏
代码如下:
分享四:一款python代码的数字猜谜小游戏
代码如下:
分享五:一段好玩的Python爬虫代码
这几年网络爬虫很火,用Python语言实现网络爬虫最合适不过了,接下来分享一段好玩的爬虫代码:
分享六、木马程序常用的键盘记录功能实现
Python keylogger键盘记录的功能的实现主要利用了pythoncom及pythonhook,然后就是对windows API的各种调用。Python之所以用起来方便快捷,主要归功于这些庞大的支持库,正所谓"人生苦短,快用Python"。
代码如下:
分享七:用Python写一个机器人陪自己聊聊天吧
用Python写一个机器人陪自己聊聊天吧。是不是听起来就很酷,用Python语言、itchat库、图灵机器人就可以轻松实现。
1. 需要的工具
- Python。写代码的工具;
- itchat库。第三方库,用来登录微信,接收并回复微信好友信息;
- 图灵机器人。第三方接口,我们本次使用的机器人;
2. 代码如下:
(1) 准备
导入需要使用的第三方库
(2) 获取来自机器人的回复信息
在这里,调用图灵机器人库,把我们接收到的微信好友信息发给图灵机器人,再取回机器人回复的信息,回复给好友。
这里要用到图灵机器人的接口,到图灵机器人官网(http://www.tuling123.com)注册登陆之后,生成一个属于个人的免费接口,免费接口一天只能用1000条,虽然不多,但娱乐一下自己也是足够的了。
创建机器人成功之后会得到apikey,把这串密码放到代码中的"key"里,这一步就完成了。
(3) 接受来自好友之间的对话信息
(4) 接受来自微信群里面的对话信息
如果不需要机器人在群聊里聊天,可以删除这块代码。
(5) 运行
最后一步,登录微信,并运行机器人。