有趣的python小程序
標簽:python
Tags:python
強調(diào):文章非原創(chuàng) 點擊查看原創(chuàng)文章
1.密碼生成器
代碼塊
x=int(input())
print(''.join(__import__('random').choice('QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm!@#$%^&*()_+=}{[]:;<,.>?/1234567890') for i in range(x)))
運行結(jié)果
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)
運行結(jié)果
輸入指定日期即可穿越(只能到未來)
請輸入目標年月日:
年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()
運行結(jié)果
圖片
圖片
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)
強調(diào):文章非原創(chuàng) 點擊查看原創(chuàng)文章