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

用Python代码写一个猜拳小游戏

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

用Python代码写一个猜拳小游戏

import random                

fail_count = 0
win_count = 0

print("这是一个猜拳游戏")
print("游戏开始,请你选择一个英雄")


for x in range(3):
    hero = eval(input("请选择你的英雄:(1.曹操.2.貂蝉.3.赵子龙)"))

    if hero == 1:
        print("英雄:曹操")
    elif hero == 2:
        print("英雄:貂蝉")
    else:
        print("英雄:赵子龙")
    break

    print("您所选择的英雄是:" +str(hero))

hero_guess = eval(input("请输入石头(0),剪刀(1),布(2)"))
computer_hero = random.randint(0,2)
if hero_guess == 0:
    print('玩家:石头')
elif hero_guess == 1:
    print('玩家:剪刀')
else:
    print('玩家:布')
if computer_hero == 0:
    print('电脑:石头')
elif computer_hero == 1:
    print('电脑:剪刀')
else:
    print('电脑:布')


if hero_guess == computer_hero:
    print("平局")

elif hero_guess == 0 and computer_hero == 1 or hero_guess == 1 and computer_hero == 2  or hero_guess == 2  and computer_hero == 0:
    print("您的英雄{0},居然赢了电脑!".format(hero))
    win_count += 1

else:
    print("没事啦,下次加油")
    fail_count += 1

print("您一共赢了{0}:".format(win_count))
print("您一共输了{0}:".format(fail_count))



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

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

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