有趣简单的python程序代码,有什么好玩的python代码

大家好,小编来为大家解答以下问题,一个简单又好玩的python代码手机版,一个简单又好玩的python代码教程,今天让我们一起来看看吧!

原标题:搞几款由"Python”语言编写的"有趣、恶搞、好玩”的程序代码!

为提高大家对"Python”编程语言的学习兴趣,今天给大家分享几款有趣的Python程序代码,感兴趣的小伙伴可以跟着学习借鉴哦!进群:839383 765可以获取Python学习资料哦!

分享一:"啥是佩奇?"让Python语言告诉你

a709525cb5f14cb6a2c2363e11ac498e.jpeg

用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()

效果图如下:

4f79faa54c5d405597043e7b63d830fc.jpeg

分享二:一个可以套路别人的python小程序

程序是使用pycharm工具,python语言所写。程序包括客户端 client.py 和服务器端 server.py 两部分,利用了python中的socket包不学python可以学c语言吗

使用方法:

首先,你需要你和你的朋友在同一个局域网内,然后在你的主机上,运行服务器端 server.py。

然后,让你的朋友在他的电脑上运行客户端 client.py。

此时你朋友电脑的windows用户密码,就会变成一个随机密码,且这个生成的随机密码他本人无法得知,而是把这个密码通过socket传给了服务器端的你。

嗯,然后你朋友的电脑密码就只有你自己知道了~

上代码:

5a17dce0c7d741a6aa1cf9c6f8f4a9a0.jpeg

分享三:一段Python 恶搞代码

代码运行后windows将无限锁屏

代码如下:

9a018e33c16b47f2b53a560df547a35e.jpeg

分享四:一款python代码的数字猜谜小游戏

代码如下:

ca4ad4ec9e2e4c90834d68636f1ef0ce.jpeg

分享五:一段好玩的Python爬虫代码

这几年网络爬虫很火,用Python语言实现网络爬虫最合适不过了,接下来分享一段好玩的爬虫代码:

773530a278794eb2a2b8238b7694a6aa.jpeg

23a224911a4a44d8a8027476f997db04.jpeg

分享六、木马程序常用的键盘记录功能实现

Python keylogger键盘记录的功能的实现主要利用了pythoncom及pythonhook,然后就是对windows API的各种调用。Python之所以用起来方便快捷,主要归功于这些庞大的支持库,正所谓"人生苦短,快用Python"。

代码如下:

128fcaa9d50144f085361e2fe1103581.jpeg

6162f0ae31854bf5b353fdf14ff337cb.jpeg

分享七:用Python写一个机器人陪自己聊聊天吧

用Python写一个机器人陪自己聊聊天吧。是不是听起来就很酷,用Python语言、itchat库、图灵机器人就可以轻松实现。

1. 需要的工具

Python。写代码的工具;

itchat库。第三方库,用来登录微信,接收并回复微信好友信息;

图灵机器人。第三方接口,我们本次使用的机器人;

2. 代码如下:

(1) 准备

导入需要使用的第三方库

48fb78daeb9a4adca710005973349a0b.jpeg

(2) 获取来自机器人的回复信息

在这里,调用图灵机器人库,把我们接收到的微信好友信息发给图灵机器人,再取回机器人回复的信息,回复给好友。

69a2e727db3649fdb15f17194cf0bf52.jpeg

这里要用到图灵机器人的接口,到图灵机器人官网(http://www.tuling123.com)注册登陆之后,生成一个属于个人的免费接口,免费接口一天只能用1000条,虽然不多,但娱乐一下自己也是足够的了。

618e233dc64f459d87df48c9f893bb7f.jpeg

创建机器人成功之后会得到apikey,把这串密码放到代码中的"key"里,这一步就完成了。

9861e720697e4d10a474949537721cc4.jpeg

(3) 接受来自好友之间的对话信息

559e7b7fdb524cf49e77765b3431d625.jpeg

(4) 接受来自微信群里面的对话信息

如果不需要机器人在群聊里聊天,可以删除这块代码。

de8c37e2469b430c9a5ed1a0a442caaa.jpeg

(5) 运行

最后一步,登录微信,并运行机器人。

责任编辑:

  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值