2019-01-20

有趣的python小程序

标签:python
Tags:python
强调:文章非原创 点击查看原创文章

1.密码生成器

代码块

x=int(input())
print(''.join(__import__('random').choice('QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm!@#$%^&*()_+=}{[]:;<,.>?/1234567890') for i in range(x)))

运行结果

16
IMHxl0+I_u8%)NnF

2.时光机

代码块

import time
import datetime
import sys
print('输入指定日期即可穿越(只能到未来)'"\n"'请输入目标年月日:')
y=int(input('年'))
m=int(input('月'))
d=int(input('日'))
sj=str(y)+' '+str(m)+' '+str(d)
d1=datetime.datetime(y,m,d)
print('启动中,还需要')
while True:
   d2=datetime.datetime.now()
   sec=round((d1-d2).total_seconds())
   op=[int(sec/86400),'天',int((sec-int(sec/86400)*86400)/3600),'小时',int((sec-int(sec/3600)*3600)/60),'分',int((sec-int(sec/60)*60)),'秒']
   nn=(''.join('%s' %id for id in op))
   sys.stdout.write("\r%s"%nn)
   sys.stdout.write('即可启动')
   sys.stdout.flush()
   time.sleep(1)

运行结果

输入指定日期即可穿越(只能到未来)
请输入目标年月日:
年2018
月9
日5
启动中,还需要
6天1小时55分3秒即可启动

3.QQ群机器人

需安装qqbot模块,图灵机器人最好自己申请一个。
@机器人可以聊天,两个空格再加文本可自动翻译

代码块

import urllib.parse
import urllib.request
import requests,json
from qqbot import QQBotSlot as qqbotslot,RunBot

@qqbotslot
def onQQMessage(bot,contact,member,content):
    def save(name,content):
        with open(name, 'w') as f:
            f.write(content)
    def tuling(info):
        url = 'http://www.tuling123.com/openapi/api?key=d846628468214520b1047b1ed0038fb1'+'&info='+info
        res = requests.get(url)
        res.encoding = 'utf-8'
        jd = json.loads(res.text)
        return jd['text']

    if '@ME' in content or '@Fabot' in content:#Fabot是我给机器人起的名字
        bot.SendTo(contact,tuling(content[4:]))
    if(content[0]==' '):
        url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=http://fanyi.youdao.com/'
        data = {
            'i': content[1:],
            'doctype': 'json',
        }
        data=urllib.parse.urlencode(data).encode('utf-8')
        response=urllib.request.urlopen(url,data)
        html=response.read().decode('utf-8')
        target=json.loads(html)
        bot.SendTo(contact,target['translateResult'][0][0]['tgt'])

RunBot()

运行结果

图片

4.弹钢琴

代码块

import winsound
tone={'1':532,'2':588,'3':660,'4':698,'5':784,'6':880,'7':988}
while True:
    winsound.Beep(tone[input()],300)

强调:文章非原创 点击查看原创文章

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 关于单位迟到现象的论述 冬天是刺骨的,在寒冷的冬天中,尽管人们把自己包裹成粽子,却也免不了一阵狂风,透过丝...
    烤地瓜_2c04阅读 256评论 0 2
  • 第二篇爬虫项目实操:运用requests库、BeautifulSoup库爬取简书专题 ---- “数据蛙每周交作业...
    夜希辰阅读 1,226评论 1 3
  • 越过山丘,才发现无人等候 年少不听李宗盛,听懂已是不惑年 李宗盛是华语乐坛的音乐教父,却也有你不知道的他 木匠李宗...
    孵不出小鸡的鸡蛋阅读 234评论 0 0
  • 如何控制自己的人生,在我看来,首先要控制自己的情绪,因为,在情商之前,先有情绪管理! 什么是情绪?百度百科...
    在途中YH阅读 895评论 0 0
  • 今天补上昨天的,给大家带来动物妙想国系列《猴子会玩滑水吗?》、睡前读物《月亮,生日快乐》、神奇的翻页书《变,变,变...
    敦敦的睡前绘本馆阅读 464评论 0 1