注意:必须在猿编程里的代码实验室运行,因为里面有猿编程的新型库,暂未与python同步。
下面的代码是一个apps.py文件的,是一个作者的原创库
import ybc_ui as ui
import random
import ybc_tools as tools
from time import sleep
import ybc_ai as ai
import ybc_data as data
import ybc_browser as boser
import ybc_pandas as pd
import ybc_jieba
import ybc_charts as charts
import ybc_jieba
import ybc_ai as ai
import ybc_sms as sms
import ybc_pandas as pd
import ybc_charts as charts
import ybc_analyze
import ybc
import ybc_animal
import ybc_app
import ybc_app_data
import ybc_app_ui
import ybc_calendar
import ybc_camera
import ybc_db
import ybc_image as im
import ybc_music
import ybc_pinyin
import ybc_pic_search
import ybc_player
import ybc_qrcode
import ybc_recognition
import ybc_wordcloud
##################备用数据库#########################
###################可随时调取########################
urlinfo = {
'百度':'www.baidu.com',
'必应':'www.bing.cn',
'百度百科':'baike.baidu.com',
'百度汉语':'hanyu.baidu.com',
'搜狗':'sogou.com',
'360':'https://www.so.com',
'谷歌':'google.com',
'新浪网':'sina.com.cn',
'猿编程官网':'https://www.ybccode.com/?keyfrom=ybc-tf-WO-wZ-S07KZ5DA',
'酷我':'www.kuwo.com',
'AICE':'e.aice.org.cn',
'西瓜视频':'www.xigua.com'
}
def sxt_snj():
while True:
i = random.choice(['加法','减法','乘法','除法'])
if i == '加法':
j = random.randint(1,1000)
k = random.randint(1,1000)
l = ui.input_int(str(j) + '+' + str(k) + '=?','image/请输入.jpeg')
if l == j + k:
continue
else:
ui.message('错误,正确答案为:' + str(j + k))
break
elif i == '减法':
m = random.randint(500,1000)
n = random.randint(1,500)
o = ui.input_int(str(m) + '-' + str(n) + '=?','image/请输入.jpeg')
if o == m - n:
continue
else:
ui.message('错误,正确答案为' + str(m - n))
break
elif i == '乘法':
p = random.randint(1,50)
q = random.randint(1,50)
r = ui.input_int(str(p) + '×' + str(q) + '=?','image/请输入.jpeg')
if r == p * q:
continue
else:
ui.message('错误,正确答案为' + str(p * q))
break
elif i == '除法':
s = random.randint(9,81)
t = random.randint(1,9)
u = ui.input(str(s) + '÷' + str(t) + '=? (商和余数用分号";"隔开,英文中文都可以)','image/请输入.jpeg')
v = str(int(s / t))
w = str(s % t)
if u == v + ';' + w or v + ';' + w:
continue
else:
ui.message('错误,正确答案为' + v + ';' + w)
break
def time_jsq():
j1 = ui.input_int('请输入计时秒数','image/请输入.jpeg')
sleep(j1)
ai.speak('时间到!',6)
def en2zh_and_zh2en():
k1 = ui.picker_button('请输入您需要的功能',['英译中','中译英'])
if k1 == '英译中':
k2 = ui.input('请输入需要转成中文的英文','image/请输入.jpeg')
k3 = ai.en2zh(k2)
ui.message('您输入的英文:' + ' ' + k2 + ' ' + '转成中文的结果为:' + ' ' + k3)
elif k1 == '中译英':
k4 = ui.input('请输入需要转成英文的中文','image/请输入.jpeg')
k5 = ai.zh2en(k4)
ui.message('您输入的中文:' + k4 + '转成英文的结果为' + k5)
def photo_zxgn():
while True:
l1 = ui.input('请输入你希望的这张照片的名字','image/请输入.jpeg')
if l1 == None or l1 == '':
ui.message('请输入合理的照片名字!!!')
continue
else:
l2 = tools.camera('image/' + l1 + '.jpg')
l3 = ui.picker_button('请问是否再拍一张?',['好的','不了,谢谢'])
if l3 == '好的':
l4 = ui.picker_button('请问是否操作?',['是','否'])
if l4 == '是':
continue
else:
break
else:
break
def photo_xc():
while True:
xc = ui.picker_file('请选择照片')
ui.image(xc)
xc1 = ui.picker_button('请问是否继续查看?',['是','否'])
if xc1 == '是':
continue
else:
break
def sxt_pg():
n1 = ui.picker_file('请选择图片')
n2 = ai.arithmetic_info(n1)
if n2 == -1:
ui.message('请选择有算式的图片哦')
else:
for n3 in n2:
if n3['对错'] == 0:
ui.message(n3['算式'] + '×')
else:
ui.message(n3['算式'] + '√')
def animal():
ui.message('本功能针对家里有宠物的用户开放,如果不慎点错,请选择"退出"按钮')
while True:
o1 = ui.picker_button('请选择:',['识别动物品种功能','识别动物信息功能','识别并获取动物百科功能','识别动物种类功能','退出'])
if o1 == '识别动物品种功能':
o2 = ui.picker_file('请选择图片')
o3 = ai.animal_breed(o2)
if o3 == -1:
ui.message('请选择有动物的图片')
break
else:
ui.message(o3)
continue
elif o1 == '识别动物信息功能':
o4 = ui.picker_file('请选择图片')
o5 = ai.animal_info(o4)
if o5 == -1:
ui.message('请选择有动物的图片')
break
else:
ui.message(o5)
continue
elif o1 == '识别并获取动物百科功能':
o6 = ui.picker_file('请选择图片')
o7 = ai.animal_desc(o6)
if o7 == -1:
ui.message('请选择有动物的图片')
break
else:
ui.message(o7)
continue
elif o1 == '识别动物种类功能':
o8 = ui.picker_file('请选择图片')
o9 = ai.animal_what(o8)
if o9 == -1:
ui.message('请选择有动物的图片')
break
else:
ui.message(o9)
continue
elif o1 == '退出':
break
def face():
while True:
p1 = ui.picker_button('请选择:',['识别人脸信息程序','人脸对比程序','性别识别功能','情绪检测功能','魔法换脸功能','识别年龄功能','识别颜值功能','识别戴不戴眼镜功能','退出'])
if p1 == '识别人脸信息程序':
while True:
tools.camera('image/3.jpg')
p2 = ai.face('image/3.jpg')
ui.message(p2)
p3 = ui.picker_button('请问您还需要继续下一轮识别吗',['继续','不继续'])
if p3 == '继续':
continue
else:
break
elif p1 == '人脸对比程序':
while True:
tools.camera('image/1.jpg')
tools.camera('image/2.jpg')
p4 = ai.face_compare('image/1.jpg','image/2.jpg')
ui.message('两张人脸的相似度是:' + p4)
p5 = ui.picker_button('请问您还需要继续下一轮对比吗',['继续','不继续'])
if p5 == '继续':
continue
else:
break
elif p1 == '退出':
break
elif p1 == '性别识别功能':
while True:
tools.camera('image/4.jpg')
p6 = ai.face_gender('image/4.jpg')
ui.message(p6)
p7 = ui.picker_button('请问您还需要继续识别吗?',['继续','不继续'])
if p7 == '不继续':
break
elif p7 == '继续':
continue
elif p1 == '情绪检测功能':
while True:
tools.camera('image/5.jpg')
p8 = ai.face_mood('image/5.jpg')
ui.message(p8)
p9 = ui.picker_button('请问您还需要继续识别吗?',['继续','不继续'])
if p9 == '不继续':
break
elif p9 == '继续':
continue
elif p1 == '魔法换脸功能':
while True:
tools.camera('image/6.jpg')
p10 = random.randint(1,14)
p11 = ai.face_magic('image/6.jpg',p10)
ui.image(p11)
p12 = ui.picker_button('请问您还需要继续换脸吗',['需要','不需要'])
if p12 == '不需要':
break
elif p12 == '需要':
continue
elif p1 == '识别年龄功能':
while True:
tools.camera('image/7.jpg')
p13 = ai.face_age('image/7.jpg')
ui.message(p13)
p14 = ui.picker_button('请问您还需要继续识别吗?',['需要','不需要'])
if p14 == '不需要':
break
elif p14 == '需要':
continue
elif p1 == '识别颜值功能':
while True:
tools.camera('image/8.jpg')
p15 = ai.face_beauty('image/8.jpg')
ui.message(p15)
p16 = ui.picker_button('请问您还要继续识别吗',['需要','不需要'])
if p16 == '需要':
continue
elif p16 == '不需要':
break
elif p1 == '识别戴不戴眼镜功能':
while True:
tools.camera('image/9.jpg')
p17 = ai.face_glasses('image/9.jpg')
ui.message(p17)
p18 = ui.picker_button('请问您还需要继续识别吗?',['需要','不需要'])
if p18 == '不需要':
break
elif p18 == '需要':
continue
def news():
while True:
q1 = ui.picker_button('请问您需要查询什么类型的新闻',['头条','民众','自然','法治','科技','退出'])
if q1 == '头条':
q2 = data.news('头条')
for q3 in q2:
ui.message(q3)
elif q1 == '民众':
q4 = data.news('民众')
for q5 in q4:
ui.message(q5)
elif q1 == '自然':
q6 = data.news('自然')
for q7 in q6:
ui.message(q7)
elif q1 == '法治':
q8 = data.news('法治')
for q9 in q8:
ui.message(q9)
elif q1 == '科技':
q10 = data.news()
for q11 in q10:
ui.message(q11)
elif q1 == '退出':
break
def fk():
fk1 = {
'功能少':'',
'没必要的运行时间很长':'',
'运行出现bug':'',
'体验感不够丝滑':'',
'功能不够简介,有不必要的内容':'',
'其他':''
}
fk6 = ui.picker_multi('请问您投诉的内容大致是:?',fk1)
fk2 = ui.input_textarea('请进一步说明内容问题','请输入内容,我们会通过后台发送','image/请输入.jpeg')
fk3 = ui.picker_button('您对本程序最终的评价是:',['✰','✰✰','✰✰✰','✰✰✰✰','✰✰✰✰✰'])
fk4 = open('意见反馈.txt','w')
fk5 = '{' + str(fk6) + ' , ' + str(fk2) + ' , ' + str(fk3) + '}'
fk4.write(fk5)
import ybc
ybc.sms(fk5)
ui.message('反馈已提交!')
#############################魔王征服者###########################
def game_mwzfz():
import ybc_ui
import random
dj1 = 0
dj2 = 0
dj3 = 0
dj4 = 0
dj5 = 0
dj6 = 0
dj7 = 0
d = {
'生命' : 100,
'攻击' : 15,
'防御' : 5,
'敏捷' : 12,
'智力' : 10,
'金币' : 50
}
ybc_ui.message(' 神秘大陆上的居民正享受着和平时光。突然!一道黑暗魔法从天而降,让整个大陆笼罩在一片阴影之中。...魔王来了...他在大陆各处安排了一系列的阴谋和陷阱,试图将这个美好的大陆变成他的恶魔王国。', 'images/魔王.png')
ybc_ui.message(' 你是一位普通的村民,意外发现自己具有一些神秘的力量。这些力量让你能够对抗魔王的邪恶势力,成为了大陆上的最后一道防线。\n 于是,你开始了冒险之旅...', 'images/主角.png')
while True:
op = ybc_ui.picker_button(d, [ '挑战魔王', '探索野外', '福利','退出游戏'])
if op == '挑战魔王':
s = d['攻击'] + d['防御'] + d['敏捷'] + d['智力']
if s > 60:
ybc_ui.message('面对强大的你,魔王毫无招架之力,很快就被你击败了。你成为了拯救世界的英雄,在人们的欢呼声中,你感觉如释重负,却又有一种失去了目标的空虚感。不久之后,你又踏上了新的旅途。')
ybc_ui.message('已达成结局:魔王梦魇')
break
else:
op = ybc_ui.picker_button('魔王瞪着你,强大的威压让你动不了,看来还需要先磨炼自己', ['强行挑战', '返回'],'images/战神之力.png')
if op == '强行挑战':
ybc_ui.message('你用尽浑身解数攻击魔王,却无济于事。你的攻击对魔王来说似乎不痛不痒,感到厌烦的魔王随手一挥,你就败下阵来。')
ybc_ui.message('已达成结局:以卵击石')
break
elif op == '探索野外':
a = random.randint(1, 12)
if a == 1:
a0 = ybc_ui.picker_button('神秘商人正在贩卖魔法斗篷,是否用10金币与其交易?', ['是', '否'], 'images/神秘商人.png')
if a0 =='是':
if d['金币'] >= 10:
d['智力'] = d['智力'] + 2
d['金币'] = d['金币'] - 10
ybc_ui.message('金币-10,获得魔法斗篷,智力+2')
else :
ybc_ui.message('金币不足')
else:
ybc_ui.message('神秘商人失望的看着你:有缘再见')
elif a == 2:
ybc_ui.message('遭遇马蜂强盗,看来不得不战斗了!', 'images/马蜂强盗.png')
temp1 = random.randint(2, 8)
temp2 = random.randint(2, 5)
d['金币'] = d['金币'] + temp1
d['生命'] = d['生命'] - temp2
ybc_ui.message('击败马蜂强盗,失去' + str(temp2) + '生命值,' + '获得' + str(temp1) + '金币')
if d['生命'] < 0:
ybc_ui.message('生命值不足,游戏失败,请重新开始')
break
elif a == 3:
d['金币'] = d['金币'] - 10
ybc_ui.message('四手神偷偷偷偷走了金币', 'images/神偷.png')
ybc_ui.message('失去10金币')
elif a == 4:
a3 = ybc_ui.picker_button('路过的怪物学校放学了,门口的杂货商正在贩卖物品', ['购买物品', '离开'], 'images/杂货商.png')
if a3 == '购买物品':
op3 = ybc_ui.picker_button('选择物品', ['辣条(10金币)', '玩具法杖(50金币)', '离开'])
if op3 == '辣条(10金币)' and d['金币'] >= 10:
d['生命'] = d['生命'] + 10
d['金币'] = d['金币'] - 10
ybc_ui.message('生命值 + 10')
if d['生命'] > 100:
ybc_ui.message('生命值上限为100')
d['生命'] = 100
elif op3 == '玩具法杖(50金币)' and d['金币'] >= 50:
d['攻击'] = d['攻击'] + 2
d['防御'] = d['防御'] + 2
d['敏捷'] = d['敏捷'] + 2
d['智力'] = d['智力'] + 2
d['金币'] = d['金币'] - 50
ybc_ui.message('全属性 + 2')
elif op3 == '离开':
ybc_ui.message('你头也不回的离开了')
else:
ybc_ui.message('金币不足,你遗憾的离开了')
else:
ybc_ui.message('你头也不回的离开了')
elif a == 5:
a4 = ybc_ui.picker_button('遇到了迷路的兰兰,是否帮助它回家?', ['是', '否'], 'images/兰兰.png')
if a4 == '是':
temp = random.randint(1, 5)
d['敏捷'] = d['敏捷'] + 2
d['生命'] = d['生命'] - temp
ybc_ui.message('树林里险象环生,失去' + str(temp) + '生命值,' + '敏捷+2')
if d['生命'] < 0:
ybc_ui.message('生命值不足,游戏失败,请重新开始')
break
else:
ybc_ui.message('你无情的离开了,兰兰留下了眼泪')
elif a == 6:
a5 = ybc_ui.picker_button('一个可疑的流浪精灵在路边向你贩卖武功秘籍,是否购买?', ['是', '否'], 'images/流浪精灵.png')
if a5 == '是':
if d['金币'] >= 50:
d['攻击'] = d['攻击'] + 1
d['金币'] = d['金币'] - 50
ybc_ui.message('花费了50金币,获得武功秘籍,攻击+1,你感觉被骗了...')
else:
ybc_ui.message('金币不足,你向流浪精灵展示了干瘪的钱包,也许它比你更富有')
else:
ybc_ui.message('流浪精灵无所谓的走开了,你感觉自己的智力增加了')
ybc_ui.message('智力+1')
d['智力'] = d['智力'] + 1
elif a == 7:
a6 = ybc_ui.picker_button('一名上了年纪的武僧认为你很有潜力,想要传授给你“金钟罩”功法', ['接受', '离开'], 'images/武僧.png')
if a6 == '接受':
d['防御'] = d['防御'] + 3
d['敏捷'] = d['敏捷'] - 1
ybc_ui.message('防御力+3,敏捷-1')
else:
ybc_ui.message('你拒绝了武僧,但你们相谈甚欢,临走前他给了你一个抱抱')
elif a == 8:
ybc_ui.message('遇到隐居深山的治愈精灵,它可以治愈所有的伤病,但不能起死回生。', 'images/治愈精灵.png')
d['生命'] = 100
ybc_ui.message('治愈精灵补满了你的生命值。')
elif a == 9:
ybc_ui.message('遭遇小拳头恶魔,看来不得不战斗了!', 'images/小拳头恶魔.png')
temp1 = random.randint(5, 20)
temp2 = random.randint(1, 10)
d['金币'] = d['金币'] + temp1
d['生命'] = d['生命'] - temp2
ybc_ui.message('击败小拳头恶魔,失去' + str(temp2) + '生命值,' + '获得' + str(temp1) + '金币')
if d['生命'] < 0:
ybc_ui.message('生命值不足,游戏失败,请重新开始')
break
elif a == 10:
ybc_ui.message('获得了小精灵的祝福,提升随机属性', 'images/祝福小精灵.png')
temp = random.choice(['攻击', '防御', '敏捷', '智力'])
d[temp] = d[temp] + 1
ybc_ui.message('在小精灵的祝福下,' + temp + '+1')
elif a == 11:
a11 = ybc_ui.picker_button('找到了年久失修的机甲巨龙,似乎可以进入他的内部看看', ['探索内部', '借他的身体乘凉'], 'images/机甲巨龙.png')
if a11 == '探索内部':
temp = random.randint(1, 5)
d['生命'] = d['生命'] - temp
ybc_ui.message('被破损的零件所伤,生命-' + str(temp))
if d['生命'] < 0:
ybc_ui.message('生命值不足,游戏失败,请重新开始')
break
d['攻击'] = d['攻击'] + 2
ybc_ui.message('找到一本古老魔法书,学习了古代魔法,攻击+2')
else:
d['生命'] = d['生命'] + 10
ybc_ui.message('你在机械巨龙巨大的身体下乘凉,获得了短暂的休息,生命+10')
if d['生命'] > 100:
ybc_ui.message('生命值上限为100')
d['生命'] = 100
elif a == 12:
a1 = ybc_ui.picker_button('遇到正在休息的怪物团伙,似乎没有发现你的存在。', ['偷袭', '离开'], 'images/怪物团伙.png')
if a1 == '偷袭' :
temp1 = random.randint(10, 30)
temp2 = random.randint(5, 10)
d['金币'] = d['金币'] + temp1
d['生命'] = d['生命'] - temp2
ybc_ui.message('怪物们四散奔逃,你失去' + str(temp2) + '生命值,' + '获得' + str(temp1) + '金币')
if d['生命'] < 0:
ybc_ui.message('生命值不足,游戏失败,请重新开始')
break
else:
ybc_ui.message('你离开了,怪物们没有发现你')
elif op == '退出游戏':
ybc_ui.message('你已经走得很远了,现在可以稍事休息,准备下一次的冒险。期待你下次的归来!')
break
elif op == '福利':
asdf1 = ybc_ui.picker_button('福利在一站到底app的全部答对的页面',['我点错了','继续兑换'])
if asdf1 == '我点错了':
while True:
break
if asdf1 == '继续兑换':
asdf2 = ybc_ui.input('请输入兑换码')
if asdf2 == '@game-mwzfz.10000jb':
if dj1 == 0:
asdf3 = ybc_ui.picker_button('请问您是否兑换?',['是','否'])
if asdf3 == '是':
d['金币'] = d['金币'] + 10000
dj1 = 1
while True:
break
elif asdf3 == '否':
while True:
break
elif dj1 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf2 == '@game-mwzfz.10fy':
if dj2 == 0:
asdf4 = ybc_ui.picker_button('请问您是否兑换',['是','否'])
if asdf4 == '是':
d['防御'] = d['防御'] + 10
dj2 = 1
elif asdf4 == '否':
while True:
break
elif dj2 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf2 == '@game-mwzfz.10mj':
if dj3 == 0:
asdf5 = ybc_ui.picker_button('请问您是否兑换',['是','否'])
if asdf5 == '是':
d['敏捷'] = d['敏捷'] + 10
dj3 = 1
elif asdf5 == '否':
while True:
break
elif dj3 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf2 == '@game-mwzfz.10gj':
if dj4 == 0:
asdf6 = ybc_ui.picker_button('请问您是否兑换',['是','否'])
if asdf6 == '是':
d['攻击'] = d['攻击'] + 10
dj4 = 1
elif asdf6 == '否':
while True:
break
elif dj4 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf2 == '@game-mwzfz.10zl':
if dj5 == 0:
asdf7 = ybc_ui.picker_button('请问您是否兑换',['是','否'])
if asdf7 == '是':
d['智力'] = d['智力'] + 10
dj5 = 1
elif asdf7 == '否':
while True:
break
elif dj5 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf3 == '@game-mwzfz.all10':
if dj6 == 0:
asdf8 == ybc_ui.picker_button('请问您是否兑换',['是','否'])
if asdf8 == '是':
d['攻击'] = d['攻击'] + 10
d['防御'] = d['防御'] + 10
d['智力'] = d['智力'] + 10
d['生命'] = d['生命'] + 10
d['金币'] = d['金币'] + 10
d['敏捷'] = d['敏捷'] + 10
dj6 = 1
elif asdf8 == '否':
while True:
break
elif dj6 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
elif asdf3 == '@game-mwzfz.100sm':
if dj7 == 0:
asdf9 == ybc_ui.picker_button('请问是否兑换',['是','否'])
if asdf9 == '是':
d['生命'] = d['生命'] + 100
dj7 = 1
elif asdf9 == '否':
while True:
break
elif dj7 == 1:
ybc_ui.message('对不起,您已兑换过了')
while True:
break
def kfzjs():
ui.message('开发者:于翱睿-逐梦工作室','image/工作室图标.jpeg')
def ai_chat():
while True:
ac = ui.picker_button('请选择聊天方式',['文字','语音','退出'])
if ac == '文字':
while True:
ac1 = ui.input('请输入与AI说的话[提示:输入"退出"即可退出对话]')
if ac1 == '退出':
break
else:
ac2 = ai.chat(ac1)
ui.message(ac2)
elif ac == '语音':
while True:
tools.record('ac.mp3',300)
ac3 = ai.voice2text('ac.mp3')
ac4 = ai.chat(ac3)
ai.speak(ac4)
elif ac == '退出':
break
def data_gs():
iq = ui.input('请输入需要查询的古诗词的题目','image/请输入.jpeg')
ir = ui.input('请输入需要查询的古诗词的作者','image/请输入.jpeg')
is1 = data.poetry(iq,ir)
ui.message(is1)
def data_yzddapp():
import ybc_data
import ybc_ui
import ybc_box
#选择主题,根据主题获得题目
op1 = ybc_ui.picker_button('请选择考试内容',['体育','历史','地理','自然','常识','文学','音乐','科学'])
d = ybc_data.qa_random(op1, 10)
num = 0
#遍历字典依次取出题目
for q in d:
l = d[q]
#展示题干和选项
op = ybc_ui.picker_button(q, [l[0], l[1]])
#判断对错
if op == l[2]:
num = num + 1
#回答正确时提示正确,并展示这是第几道题
ybc_ui.message('回答正确!这是第' + str(num) + '道题目')
else:
#回答错误时提示失败,展示解析并中止循环
ybc_ui.message('挑战失败!解析如下:' + l[3])
break
if num == 10:
ybc_ui.message('恭喜你,完成了挑战,下面我们将免费给您一次抽取“魔王征服者”游戏的福利(100%哦!)')
zz = ybc_ui.picker_random('请抽取:',['10000金币','10防御','10敏捷','10攻击','10智力','100生命','各个方面均加10'])
if zz == '10000金币':
ybc_ui.message('恭喜您,获得10000金币,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.10000jb (符号全部为英文状态下输入)')
elif zz == '10防御':
ybc_ui.message('恭喜您,获得10防御,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.10fy(符号全部为英文状态下输入)')
elif zz == '10敏捷':
ybc_ui.message('恭喜您,获得10敏捷,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.10mj(符号全部为英文状态下输入)')
elif zz == '10攻击':
ybc_ui.message('恭喜您,获得10防御,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.10gj(符号全部为英文状态下输入)')
elif zz == '10智力':
ybc_ui.message('恭喜您,获得10智力,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.10zl(符号全部为英文状态下输入)')
elif zz == '100生命':
ybc_ui.message('恭喜您,获得10防御,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.100sm(符号全部为英文状态下输入)')
elif zz == '各个方面均加10':
ybc_ui.message('恭喜您,获得10防御,请到魔王征服者-福利 兑换,兑换码:@game-mwzfz.all10(符号全部为英文状态下输入)')
def data_date():
from datetime import date
today = date.today()
ui.message('今天是' + str(today))
def tools_browser():
global urlinfo
list = []
for i in urlinfo:
list.append(i)
list.append('其他')
list.append('退出')
picker = ui.picker_button('选择打开的网页',list)
if picker == list[len(list)-1]:
url = ui.input('输入网址','image/请输入.jpeg')
boser.open(url)
else:
boser.open(urlinfo[picker])
def cut():
poem = ui.input('请问您需要断句的诗词是什么')
words = ybc_jieba.cut(poem)
print(words)
t = str(words)
ai.speak(t)
def jieba_and_ai_scdj():
poem = ui.input('请输入您需要断句的诗词','image/请输入.jpeg')
words = ybc_jieba.cut(poem)
print(words)
t = str(words)
ai.speak(t)
def pandas_lb():
df = pd.read_csv('唐诗三百首.csv')
author_list = []
for a in df['作者']:
author_list.append(a)
author_count = {}
for a in author_list:
if a not in author_count:
author_count[a] = 1
else:
author_count[a] += 1
authors = list(author_count.keys())
counts = list(author_count.values())
s = pd.Series(counts,authors)
s = s.sort_values(ascending=False)
print(s)
wc = charts.Wordcloud(data=[s.index,s.values])
wc.show()
def pandas_all():
df = pd.read_csv('唐诗三百首.csv')
df1 = df[df['作者']=='李白']
word_list = []
for poetry in df1['内容']:
words = ybc_jieba.cut(poetry)
for w in words:
word_list.append(w)
word_count = {}
for w in word_list:
if w not in word_count:
word_count[w] = 1
else:
word_count[w] += 1
words = list(word_count.keys())
counts = list(word_count.values())
s = pd.Series(counts,words)
s = s.sort_values(ascending=False).head(100)
wc = charts.Wordcloud(data=[s.index,s.values])
wc.show()
def data_weather():
p = ui.picker_button('您需要哪种类型的天气预报呢?',['今天天气','一周天气'])
if p == '今天天气':
q = ui.input('请问您所在的城市是什么?','image/请输入.jpeg')
r = data.weather_today(q)
ui.message(r)
elif p == '一周天气':
s = ui.input('请问您所在的城市是什么?','image/请输入.jpeg')
t = data.weather_week(s)
ui.message(t)
def word():
ui.message('欢迎来到文档模块!')
wd = ui.input('请输入文件名(不用输入“.txt”后缀)','image/请输入.jpeg')
wd1 = ui.input_textarea('请输入内容(不能修改)','请输入你想要编辑的内容吧,注意不要超过100000字哦~~~','image/请输入.jpeg')
wd2 = open(wd + '.txt','w')
wd2.write(wd1)
wd2.close()
ui.message('保存成功!')
def provinces():
while True:
in1 = data.china_provinces()
in2 = random.choice(in1)
ui.message(in2)
in3 = ui.picker_button('请问您还需要再次抽取吗?',['再次抽取','不了,谢谢'])
if in3 == '再次抽取':
continue
else:
break
def tools_qrcode():
while True:
qr = ui.input('请输入您想要在二维码里写入的内容:','image/请输入.jpeg')
qr1 = ui.picker_button('请问是否添加彩色效果',['是','否'])
if qr1 == '是':
ybc.colorqrcode(qr)
if qr1 == '否':
tools.qrcode(qr)
def kw():
while True:
kw = ui.input('请输入课文名称','image/请输入.jpeg')
if kw == None:
continue
kw1 = data.article(kw)
if kw1 == -1:
ui.message('没有找到你查询的课文')
continue
kw2 = open(kw1,'r')
kw3 = kw2.read()
kw2.close()
ui.message(kw3)
kw4 = ui.picker_button('请问是否继续查询?',['是','否'])
if kw4 == '是':
continue
else:
break
以上代码定义了各种功能
下面的代码是一个作者用于防伪的代码,取名:fw.py:
def _():
print('逐梦出品,必属精品')
下面的代码是一个大型的前端选择(选择“手机的功能”)
这里就运用了上面apps.py的功能,取名app.py
def run_this_app_and_go():
import ybc_ui as ui
import ybc_ai as ai
import ybc_data as data
import ybc_tools as tools
import random
from time import sleep
import math
from ybc import sms
import ybc_sms
import apps
import fw
import tools_box
import ybc_app
###################备用数据库######################
##想要克隆的,必须给我玩出点新花样##
##有隐藏标识,休想抄袭,禁止复制!##
##运行体验程序吧##
##꧁♛꧂##
##꧁♚꧂##
##逐梦工作室出品,必属精品##
fw._()
number = random.randint(10000000,99999999)
name = ui.input('请输入用户名(可以不输入)')
if name == None or name == '':
name = '用户' + str(number)
else:
name = name
# 设置主循环
print('开始')
while True:
xz = ui.picker_button('欢迎' + str(name) + '登录!\n꧁♛꧂\n꧁♚꧂',['开发者介绍','创意画板(评论区)','魔王征服者','浏览器','一站到底app','诗词断句','李白诗词云图','唐诗三百首诗词云图','文档','日历','查询课文功能','动物系列功能','人脸系列功能','人工智能聊天','刷数学题功能','天气预报功能','计时器','中译英&英译中功能','新闻功能','生成二维码功能','照相功能','相册','随机抽取数字功能','成语猜猜乐小程序','整数转换二进制数功能','自动判卷功能','随机抽取汽车品牌功能','随机抽取中国城市功能','随机抽取中国省份功能','意见反馈','查询古诗词功能','计算器','单词转换摩斯电码','迭代说明','退出'])
print(xz)
print('丨')
if xz == '开发者介绍':
apps.kfzjs()
elif xz == '创意画板(评论区)':
ybc_app.show_page('page1')
ybc_app.run()
elif xz == '人工智能聊天':
apps.ai_chat()
elif xz == '日历':
apps.data_date()
elif xz == '退出':
break
elif xz == '天气预报功能':
apps.data_weather()
elif xz == '生成二维码功能':
apps.tools_qrcode()
elif xz == '随机抽取数字功能':
while True:
a = ui.input_int('请输入起始数字','image/请输入.jpeg')
b = ui.input_int('请输入终止数字(1-99999999999999)','image/请输入.jpeg')
b1 = int(b)
if b1 and a == None or b1 and a == '' or b1 > 99999999999999:
ui.message('请您输入合理的数字')
continue
b2 = random.randint(a,b1)
ui.message('您生成的数字如下:' + str(b2))
elif xz == '成语猜猜乐小程序':
while True:
s = data.idiom()
q = s[0] + '_' + s[2] + s[3]
a = ui.input(q,'image/请输入.jpeg')
if a == s[1]:
ui.message('正确')
else:
ui.message('错误,正确答案是:' + s)
break
elif xz == '人脸对比程序':
while True:
tools.camera('image/1.jpg')
tools.camera('image/2.jpg')
b = ai.face_compare('image/1.jpg','image/2.jpg')
ui.message('两张人脸的相似度是:' + str(b))
c = ui.picker_button('请问您还需要继续下一轮对比吗',['继续','不继续'])
if c == '继续':
continue
else:
break
elif xz == '整数转换二进制数功能':
f = ui.input_int('请输入需要转换成为二进制数的整数','image/请输入.jpeg')
g = bin(f)
ui.message('转换为的二进制数为' + g)
elif xz == '随机抽取汽车品牌功能':
while True:
h = data.car_brands()
ii = random.choice(h)
ui.message('您随机抽取的汽车品牌如下:' + ii)
ij = ui.picker_button('请问您还需要再次抽取吗?',['再次抽取','不了,谢谢'])
if ij == '再次抽取':
continue
else:
break
elif xz == '随机抽取中国城市功能':
while True:
ik = data.china_cities()
il = random.choice(ik)
ui.message(il)
im = ui.picker_button('请问您还需要再次抽取吗?',['再次抽取','不了,谢谢'])
if im == '再次抽取':
continue
else:
break
elif xz == '随机抽取中国省份功能':
apps.provinces()
elif xz == '意见反馈':
apps.fk()
elif xz == '查询古诗词功能':
apps.data_gs()
elif xz == '计算器':
tools_box.math_jsq()
elif xz == '迭代说明':
ui.message('本版本是便捷小程序v8.0版本,v9.0版本里会添加更多功能,敬请期待吧~~~\n本期火热上线:刷数学题功能、动物系列功能。下期添加:')
elif xz == '刷数学题功能':
iu = ui.picker_button('请选择难度:',['一年级','二年级','三年级','四年级','五年级','六年级','退出'])
if iu == '一年级':
while True:
iu1 = random.choice(['加法','减法'])
if iu1 == '加法':
iu2 = random.randint(1,10)
iu3 = random.randint(1,10)
iu4 = ui.input_int(str(iu2) + '+' + str(iu3) + '=?','image/请输入.jpeg')
if iu4 == iu2 + iu3:
continue
else:
ui.message('错误,正确答案为:' + str(iu2 + iu3))
break
elif iu1 == '减法':
iu5 = random.randint(10,20)
iu6 = random.randint(0,10)
iu7 = ui.input_int(str(iu5) + '-' + str(iu6) + '=?','image/请输入.jpeg')
if iu7 == iu5 - iu6:
continue
else:
ui.message('错误,正确答案为:' + str(iu5 - iu6))
break
elif iu == '退出':
while True:
break
elif iu == '二年级':
while True:
iu8 = random.choice(['加法','减法','乘法'])
if iu8 == '加法':
iu9 = random.randint(0,100)
iu10 = random.randint(0,100)
iu11 = ui.input_int(str(iu9) + '+' + str(iu10) + '=?','image/请输入.jpeg')
if iu11 == iu9 + iu10:
continue
else:
ui.message('错误,正确答案为' + str(iu9 + iu10))
break
elif iu8 == '减法':
iu12 = random.randint(100,200)
iu13 = random.randint(0,100)
iu14 = ui.input_int(str(iu12) + '-' + str(iu13) + '=?','image/请输入.jpeg')
if iu14 == iu12 - iu13:
continue
else:
ui.message('错误,正确答案为' + str(iu12 - iu13))
break
elif iu8 == '乘法':
iu15 = random.randint(0,10)
iu16 = random.randint(0,10)
iu17 = ui.input_int(str(iu15) + '×' + str(iu16) + '=?','image/请输入.jpeg')
if iu17 == iu15 * iu16:
continue
else:
ui.message('错误,正确答案为' + str(iu15 * iu16))
break
elif iu == '三年级':
apps.sxt_snj()
elif iu == '四年级':
apps.sxt_snj()
elif iu == '五年级':
apps.sxt_snj()
elif iu == '六年级':
apps.sxt_snj()
elif xz == '计时器':
apps.time_jsq()
elif xz == '中译英&英译中功能':
apps.en2zh_and_zh2en()
elif xz == '照相功能':
apps.photo_zxgn()
elif xz == '相册':
apps.photo_xc()
elif xz == '自动判卷功能':
apps.sxt_pg()
elif xz == '动物系列功能':
apps.animal()
elif xz == '人脸系列功能':
apps.face()
elif xz == '新闻功能':
apps.news()
elif xz == '单词转换摩斯电码功能':
apps.mosi()
elif xz == '魔王征服者':
apps.game_mwzfz()
elif xz == '一站到底app':
apps.data_yzddapp()
elif xz == '浏览器':
apps.tools_browser()
elif xz == '诗词断句':
apps.jieba_and_ai_scdj()
elif xz == '李白诗词云图':
apps.pandas_all()
elif xz == '唐诗三百首诗词云图':
apps.pandas_lb()
elif xz == '文档':
apps.word()
elif xz == None:
break
elif xz == '查询课文功能':
apps.kw()
######################################################################################################################################################################################################################################
下面是一个创意画板功能专属的三个文件,分别为:page1.py 、page2.py、 page3.py。
import ybc_app
import ybc_tools
ybc_app.bg('bg1.png')
# 组件
b_start = ybc_app.Button(image='start.png', pos=[188, 500])
s_work = ybc_app.Select(pos=[188, 582], image='select.png', option_image='option.png')
# 获取所有作品名并展示
def on_show():
dm = ybc_app.DataManager('data.txt')
res = dm.find({})
name_list = []
for i in res:
name = i['作品名']
name_list.append(name)
s_work.options = name_list
# 点击按钮跳转到创作页面
def start_draw():
ybc_app.show_page('page2')
b_start.on_click = start_draw
# 点击选项跳转到作品页面
def open_work():
name = s_work.value
ybc_app.set('作品名', name)
ybc_app.show_page('page3')
s_work.on_click = open_work
page2.py:
import ybc_app
ybc_app.bg('bg2.png')
color = 'black'
state = '未绘制'
undo_list = []
# 组件
b_back = ybc_app.Button(image='back.png', pos=[30, 30])
b_save = ybc_app.Button(image='save.png', pos=[335, 30])
b_erase = ybc_app.Button(image='erase.png', pos=[330, 580])
b_undo = ybc_app.Button(image='undo.png', pos=[330, 630])
prompt = ybc_app.Prompt(title='请输入作品名称')
alert = ybc_app.Alert(text='作品名重复!请检查!')
# 创建画板区域
rect_list = []
y = 112
for j in range(20):
x = 34
for i in range(15):
rect = ybc_app.Rect(fill_color='white', border_color='purple', border_width=1, width=22, height=22, pos=[x, y])
x += 22
rect_list.append(rect)
y += 22
# 颜色按钮组件
button_list = []
pos_list = [[95, 585], [143, 585], [191, 585], [239, 585], [95, 625], [143, 625], [191, 625], [239, 625]]
image_list = ['black.png', 'blue.png', 'purple.png', 'green.png', 'red.png', 'orange.png', 'yellow.png', 'pink.png']
for i in range(8):
button = ybc_app.Button(image=image_list[i], pos=pos_list[i])
button_list.append(button)
def on_show():
global color, undo_list
for rect in rect_list:
rect.fill_color = 'white'
color = 'black'
undo_list = []
# 触摸按下功能
def on_touch_down(pos):
global state
for rect in rect_list:
if rect.collide(pos):
rect.fill_color = color
state = '已绘制'
# 触摸移动功能
def on_touch_move(pos):
global state
for rect in rect_list:
if rect.collide(pos):
rect.fill_color = color
state = '已绘制'
# 触摸抬起功能
def on_touch_up():
global state
if state == '已绘制':
data_list = []
for rect in rect_list:
color = rect.fill_color
data_list.append(color)
undo_list.append(data_list)
state = '未绘制'
# 修改颜色
def change_color(obj):
global color
img = obj.image
color = img[0:-4]
for button in button_list:
button.on_click = change_color
# 擦除效果
def erase():
global color
color = 'white'
b_erase.on_click = erase
# 回撤效果
def undo():
if len(undo_list) != 0:
undo_list.pop()
if len(undo_list) != 0:
data_list = undo_list[-1]
for i in range(len(data_list)):
rect = rect_list[i]
color = data_list[i]
rect.fill_color = color
else:
for rect in rect_list:
rect.fill_color = 'white'
b_undo.on_click = undo
# 弹出输入提示框
def save():
prompt.open()
b_save.on_click = save
# 保存作品
def save_work():
if prompt.value == True:
name = prompt.text
dm = ybc_app.DataManager('data.txt')
res = dm.find({'作品名':name})
if len(res) == 0:
data_list = []
for rect in rect_list:
color = rect.fill_color
data_list.append(color)
dm.insert({'作品名':name, '数据':data_list})
prompt.close()
ybc_app.show_page('page1')
else:
alert.open()
prompt.on_click = save_work
# 返回首页
def back():
ybc_app.show_page('page1')
b_back.on_click = back
page3.py:
import ybc_app
ybc_app.bg('bg3.png')
color = 'black'
state = '未绘制'
undo_list = []
# 组件
b_back = ybc_app.Button(image='back.png', pos=[30, 30])
b_erase = ybc_app.Button(image='erase.png', pos=[330, 580])
b_undo = ybc_app.Button(image='undo.png', pos=[330, 630])
b_change = ybc_app.Button(image='change.png', pos=[335, 30])
b_delete = ybc_app.Button(image='delete.png', pos=[250, 30])
confirm = ybc_app.Confirm(text='你确定要删除此作品吗?')
# 创建画板区域
rect_list = []
y = 112
for j in range(20):
x = 34
for i in range(15):
rect = ybc_app.Rect(fill_color='white', border_color='purple', border_width=1, width=22, height=22, pos=[x, y])
x += 22
rect_list.append(rect)
y += 22
# 颜色按钮组件
button_list = []
pos_list = [[95, 585], [143, 585], [191, 585], [239, 585], [95, 625], [143, 625], [191, 625], [239, 625]]
image_list = ['black.png', 'blue.png', 'purple.png', 'green.png', 'red.png', 'orange.png', 'yellow.png', 'pink.png']
for i in range(8):
button = ybc_app.Button(image=image_list[i], pos=pos_list[i])
button_list.append(button)
# 展示对应作品
def on_show():
global color, undo_list
name = ybc_app.get('作品名')
dm = ybc_app.DataManager('data.txt')
res = dm.find({'作品名':name})
data = res[0]
data_list = data['数据']
for i in range(len(data_list)):
rect_list[i].fill_color = data_list[i]
color = 'black'
undo_list = []
# 触摸按下功能
def on_touch_down(pos):
global state
for rect in rect_list:
if rect.collide(pos):
rect.fill_color = color
state = '已绘制'
# 触摸移动功能
def on_touch_move(pos):
global state
for rect in rect_list:
if rect.collide(pos):
rect.fill_color = color
state = '已绘制'
# 触摸抬起功能
def on_touch_up():
global state
if state == '已绘制':
data_list = []
for rect in rect_list:
color = rect.fill_color
data_list.append(color)
undo_list.append(data_list)
state = '未绘制'
# 修改颜色
def change_color(obj):
global color
img = obj.image
color = img[0:-4]
for button in button_list:
button.on_click = change_color
# 擦除效果
def erase():
global color
color = 'white'
b_erase.on_click = erase
# 回撤效果
def undo():
if len(undo_list) != 0:
undo_list.pop()
if len(undo_list) != 0:
data_list = undo_list[-1]
for i in range(len(data_list)):
rect = rect_list[i]
color = data_list[i]
rect.fill_color = color
else:
name = ybc_app.get('作品名')
dm = ybc_app.DataManager('data.txt')
res = dm.find({'作品名':name})
data = res[0]
data_list = data['数据']
for i in range(len(data_list)):
rect = rect_list[i]
color = data_list[i]
rect.fill_color = color
b_undo.on_click = undo
# 修改作品
def change():
name = ybc_app.get('作品名')
data_list = []
for rect in rect_list:
color = rect.fill_color
data_list.append(color)
dm = ybc_app.DataManager('data.txt')
dm.update({'作品名':name}, {'数据':data_list})
ybc_app.show_page('page1')
b_change.on_click = change
# 弹出确认框
def delete():
confirm.open()
b_delete.on_click = delete
# 删除作品
def delete_work():
name = ybc_app.get('作品名')
dm = ybc_app.DataManager('data.txt')
dm.delete({'作品名':name})
ybc_app.show_page('page1')
confirm.on_click = delete_work
# 返回首页
def back():
ybc_app.show_page('page1')
b_back.on_click = back
以上就是“手机”的代码,希望能帮助到你,另外,再次说明:请在猿编程里运行