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

利用列表实现石头剪刀布游戏

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

利用列表实现石头剪刀布游戏

利用列表实现石头剪刀布游戏。

import random
allList=['石头','剪刀','布']
winList=[['石头','剪刀'],['剪刀','布'],['布','石头']]
chum=-1
prompt='''
欢迎参加游戏
请选择
0 石头
1 剪刀
2 布
3 我不想玩了
请选择对应的数字
'''
while True:
    chnum=input(prompt)
    if chnum not in['0','1','2','3']:
        print("无效的选择,请选择0/1/2/3")
        continue
    if chnum=='3':
        break
    cchoice=random.choice(allList)
    uchoice=allList[int(chnum)]
    print("您选择了:{}n计算机选择了:{}".format(uchoice,cchoice))
    if uchoice==cchoice:
        print("平局")
    elif [uchoice,cchoice] in winList:
            print("你赢了!!!")
    else:
            print("你输了!!!")
print("游戏结束!")

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

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

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