前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >有趣的python小程序

有趣的python小程序

作者头像
全栈程序员站长
发布2022-07-04 13:18:12
5230
发布2022-07-04 13:18:12
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

1.密码生成器

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

运行结果:

代码语言:javascript
复制
16
IMHxl0+I_u8%)NnF

2.时光机

代码语言:javascript
复制
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)

运行结果:

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

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

代码语言:javascript
复制
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.弹钢琴

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

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/149341.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
机器翻译
机器翻译(Tencent Machine Translation,TMT)结合了神经机器翻译和统计机器翻译的优点,从大规模双语语料库自动学习翻译知识,实现从源语言文本到目标语言文本的自动翻译,目前可支持十余种语言的互译。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档