python猜拳游戏

import random
guess = {1: "剪刀", 2: "石头", 3: "布"}
while True:
    while True:
        player = int(input("玩家请出拳:1.剪刀 2.石头 3.布:"))
        if player in range(1,4):
            break
        else:
            print("玩家请重新出拳:")
    computer = random.randint(1, 3)
    print("玩家出%s,电脑出%s" % (guess[player], guess[computer]))
    if (computer == 1 and player == 3) or (computer == 2 and player == 1) or (computer == 3 and player == 2):
        print("电脑赢")
    elif computer == player:
        print("平局")
    else:
        print("玩家赢")

猜你喜欢

转载自blog.csdn.net/weixin_43693233/article/details/84834396