剪刀石头布(胜率提示)

import random

go, b = 1, 1
winRate, fail, win,ping = 0, 0, 0,0  # 胜率  失败 胜利 平局
scissors, stone, cloth = 0, 0, 0  # 剪刀  石头  布
cheat = 0  # 作弊器

print("选择任意键开始游戏,退出游戏选择n/N")
while go != 0:
    a = input()
    if a == "N" or a == "n":
        b = input("确定退出吗,如果是选择n/N")
        if b == "N" or b == "n":
            if fail == 0 and win == 0:
                break
            else:
                winRate = win / (win + fail)
                print("胜率为", winRate)
            break

    # computer = random.randint(0, 2)
    computer = 1
    if cheat == 1:
        print("机器人将出",computer)
    player1 = input("请出拳 石头(0)/剪刀(1)/布(2):")
    if (player1 != "0") and (player1 != "1") and (player1 != "2"):
        print("选择错误,是否继续游戏,继续游戏请选择任意键,退出游戏选择n/N")
        continue
    if computer == 0:
        stone = stone + 1
    elif computer == 1:
        scissors = scissors + 1
    else:
        cloth = cloth + 1
    player = int(player1)
    if (player == 0 and computer == 0) or (player == 1 and computer == 1) or (player == 2 and computer == 2):
        print("你出的是:%s" % player + ",计算机出的是%s" % computer)
        print("平局")
        ping=ping+1
    elif (player == 0 and computer == 1) or (player == 1 and computer == 2) or (player == 2 and computer == 0):
        print("你出的是:%s" % player + ",计算机出的是%s" % computer)
        print("我赢了")
        win = win + 1
    else:
        print("你出的是:%s" % player + ",计算机出的是%s" % computer)
        print("你输了")
        fail = fail + 1

        if fail != 0 and win+fail+ping>3 and winRate < 0.5:
            if (win / (win + fail)) <= 0.001:
                print("你实在是太愚蠢了,已强行开启高级作弊器")
                cheat = 1
            else :
                print("你太菜了,是否使用提示使用选择Y/y")
                prompt = input()
                if prompt == 'Y' or prompt == 'y':
                    print("机器人的猜拳情况为剪刀=", scissors, "石头=", stone, "布=", cloth)
                    if scissors > stone and scissors > cloth:
                        print("我推荐你下一句使用石头")
                    elif stone > scissors and stone > cloth:
                        print("我推荐你下一句使用布")
                    else:
                        print("我推荐你下一句使用剪刀")
    print("是否继续游戏,退出游戏选择n/N,继续游戏请选择任意键")
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值