基于Python的猜拳游戏

标题基于Python的猜拳游戏

import  random	
i=0
while 1:
    computer = random.choice(['拳头', '剪刀', '布'])
    print()
    print("规则:拳头,剪刀,布:")
    player = input("玩家出 ")
    if player =="拳头"or"剪刀"or"布":
        print("电脑出",computer)
        if((player=="拳头")and(computer=="剪刀")or((player=="剪刀")and(computer=="布"))or((player=="布")and(computer=="拳头"))):
            i += 1
            a="玩家获胜"
            print(a)
            w+=1
            print(f"第{i}轮结束 {a},第{i + 1}轮开始")

        elif player==computer:
            print("平局")

        elif((player=="拳头")and(computer=="布")or((player=="剪刀")and(computer=="拳头"))or((player=="布")and(computer=="剪刀"))):
            i += 1
            b="电脑获胜"
            print(b)
            print(f"第{i}轮结束 {b},第{i + 1}轮开始")

        elif player != "拳头" or "剪刀" or "布":
            print("输入信息有误,请重新输入")

猜你喜欢

转载自blog.csdn.net/qq_27316365/article/details/107769416