Python【猜拳游戏】

猜拳游戏:石头、剪刀、布的游戏
代码如下:




choices = ["石头", "剪刀", "布"]
player1_score = 0
player2_score = 0

while True:
    # 玩家1进行选择
    player1_choice = input("玩家1请出拳(石头、剪刀、布):")
    
    # 玩家2进行选择
    player2_choice = input("玩家2请出拳(石头、剪刀、步):")
    
    # 判断胜负并更新分数
    if player1_choice == player2_choice:
        print("平局!")
    elif (player1_choice == "石头" and player2_choice == "剪刀") or \
         (player1_choice == "剪刀" and player2_choice == "布") or \
         (player1_choice == "布" and player2_choice == "石头"):
        print("玩家1赢了!")
        player1_score += 1
    else:
        print("玩家1输了!")
        player2_choice += 1
    
    # 显示当前分数
    print(f"当前分数:玩家1 {player1_score} - {player2_score} 玩家2")
    
    # 询问是否继续游戏
    play_again = input("是否继续游戏?(输入 y 继续,其他任意键退出):")
    if play_again.lower() != "y":
        break

print("游戏结束!")

你可能感兴趣的:(Python,python,游戏,开发语言)