用户:
竹空QwQ查看:0 回复:0 评论:0 创建时间:2021-07-11T13:32:04
【作品展示】

【作品介绍】
自学easygui创作的一个动物小问答
【作品源代码】
from easygui import * # 导入easygui库
from random import * # 导入random随机库
from os import * # 导入os库
from time import * # 导入time库
from pygame import * # 导入pygame库
# 判断退出
def over():
if answer2 == None:
msgbox('退出成功!再见!')
_exit(0)
# 播放音乐
def music(mp3):
# 初始化
mixer.init()
# 加载音乐文件
track = mixer.music.load(file + mp3)
# 开始播放音乐流
mixer.music.play()
# 等待
if mp3 == "right.mp3":
sleep(1)
elif mp3 == "wrong.mp3":
sleep(2)
# 准备数据
questions = {
"树袋鼠": ["tree Kangaroo", ("树袋鼠", "树袋熊")],
"熊猫": ["panda", ("熊猫", "老鼠")],
"金丝猴": ["golden monkey", ("金丝猴", "狒狒")],
"扬子鳄": ["Alligator sinensis", ("扬子鳄", "鳄鱼")],
"华南虎": ["south china tiger", ("华南虎", "东北虎")],
"朱鹮": ["crested ibis", ("朱鹮", "丹顶鹤"), "这是什么"],
"褐马鸡": ["Brown Eared Pheasant", ("褐马鸡", "雪鸡")],
"黑颈鹤": ["Black-necked Crane", ("天鹅", "黑颈鹤")],
"藏羚羊": ["Tibetan antelope", ("藏羚羊", "山羊")],
"麋鹿": ['elk', ("梅花鹿", "麋鹿")],
}
keys = list(questions.keys())
score = 0
answer2 = None
file = r'D: \桌面\文件夹\Python参赛作品\'
# 准备界面
try:
answer1 = ccbox(msg="", title="准备答题(共十题)", choices=("准备好了", "再等等吧"), image='start.png')
except:
msgbox('请不要点击图片')
_exit(0)
# 是否开始
if answer1:
keys_n = len(keys)
while keys_n > 0:
# print(keys)
keys_n = len(keys)
# 创建题目数据
try:
key = choice(keys)
except:
break
question = questions[key]
c = question[1]
img = question[0]
answer2 = buttonbox(
msg="这是什么?",
title="答题界面",
choices=c,
image=img + ".gif")
over()
if answer2 == key:
msgbox('答对了!加一分!', "正确")
music("right.mp3")
keys.pop(keys.index(answer2))
score += 1
elif not answer2 == key and not answer2 == None and not ".gif" in answer2:
msgbox('真可惜,答错了!答案是{}'.format(key), "错误")
music('wrong.mp3')
keys.pop(keys.index(key))
elif ".gif" in answer2:
msgbox('请不要点击图片')
# 测试时跳过答题过程
# keys = []
answer2 = msgbox('你的分数是{}'.format(score))
over()
if score == 10:
msgbox('恭喜你获得“动物博士”的称号','称号')
elif score >= 5 and score > 3:
msgbox('恭喜你获得“知识渊博”的称号', '称号')
elif score >= 3 and score > 1:
msgbox('恭喜你获得“学海无涯”的称号', '称号')
elif score == 1 or score == 0:
msgbox('请好好学习,努力拿到“动物博士”的称号', '称号')
# 结尾
answer2 = msgbox('你拿到了这个称号是不是很开心呢?', "")
over()
answer2 = msgbox('这些动物是不是很可爱或漂亮呢?', "")
over()
answer2 = msgbox(
'但是他们在渐渐淡出我们的视野,有些动物甚至已经濒临灭绝:' +
'藏羚羊是现存跑的最快的动物之一,' +
'但只有两万多只,' +
'可爱的金丝猴只有千余只,' +
'被称为活化石的扬子鳄野生只有不到两百只,' +
'华南虎显存仅有不到三十只,' +
'朱鹮鸟被发现时仅有七只。', '')
over()
answer2 = msgbox('他们为什么会消失呢?')
over()
answer2 = msgbox('因为人类的过度砍伐和破坏环境,让他们越来越稀少,越来越濒临灭绝')
over()
answer2 = msgbox('为了让他们不再只出现在照片中,我们应该保护环境,让他们自由自在地生活在大自然中!')
over()
else:
over()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn