栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python抓狐狸游戏

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python抓狐狸游戏

要求:实现抓狐狸游戏。假设墙上有5个洞(编号分别为0、1、2、3、4),其中一个洞里有狐狸,人类玩家输入洞口编号,如果都里有狐狸就抓到了;如果洞里没有狐狸就第二天抓。但在第二天人类玩家来抓之前,狐狸会调到隔壁的洞里

import random
holelist = [0,0,0,0,0]
pos = random.randint(0,4)
holelist[pos] = 1

def fox(pos):
    go = random.randint(0,1)
    if pos == 0 & pos == 4:
        if(pos == 0):
            pos += 1
            olelist[pos] = 1
            holelist[pos - 1] = 0
        elif(pos == 4):
            pos -= 1
            holelist[pos] = 1
            holelist[pos + 1] = 0
    elif (go == 1):
        pos += 1
        holelist[pos] = 1
        holelist[pos-1] = 0
    elif(go == 0):
        pos -= 1
        holelist[pos] = 1
        holelist[pos+1] = 0

    return pos

while(True):
    x = int(input("请输入你要选择的洞口"))
    if(holelist[x] == 1):
        print("恭喜你抓到兔子啦!")
        break
    else:
        print("没抓到!兔子在%d洞口哦!" % pos)
        pos = fox(pos)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/887403.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号