猫史档案馆


【Python作品分享】随机怪兽生成器-小千

用户:编程猫开封运营中心编程猫开封运营中心查看:0 回复:0 评论:0 创建时间:2020-10-25T18:33:53


【作品展示】

center_image

 

【作品介绍】

随机怪兽生成器

通过随机获取列表的值自动组装成不同的内容

 

【作品源代码】

import random
mylist = [['时空魔兽', '蓝慧','火山怪鸟'],
        ['宇宙', '彩灵堡','房顶上'],
        ['引起火山爆发', '学习魔法','考试']]
temp = [[],[],[]]
while True:
    if mylist[0] and mylist[1] and mylist[2]:
        if  input('***Press Enter***见证怪兽的时刻到了:')=='':
            n = random.randint(0, len(mylist[0])-1)
            w = random.randint(0, len(mylist[1])-1)
            d = random.randint(0, len(mylist[2])-1)
            print(mylist[0][n], '在', mylist[1][w], mylist[2][d])
            x = mylist[0].pop(n)
            temp[0].append(x)
            x = mylist[1].pop(w)
            temp[1].append(x)
            x = mylist[2].pop(d)
            temp[2].append(x)
        else:
            break
    else:
        if len(mylist[0]) == 0:
            temp[0],mylist[0] = mylist[0],temp[0]
        if len(mylist[1]) == 0:
            temp[1], mylist[1] = mylist[1], temp[1]
        if len(mylist[2]) == 0:
            temp[2], mylist[2] = mylist[2], temp[2]


















































 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页