python import random while True: player_choice = input("你出石头(1)、剪刀(2)还是布(3): ") computer_choice = random.randint(1, 3) if player_choice == "1" and computer_choice == 1: print("平局!") elif player_choice == "1" and computer_choice == 2: print("你赢了!") elif player_choice == "1" and computer_choice == 3: print("你输了!") elif player_choice == "2" and computer_choice == 1: print("你输了!") elif player_choice == "2" and computer_choice == 2: print("平局!") elif player_choice == "2" and computer_choice == 3: print("你赢了!") elif player_choice == "3" and computer_choice == 1: print("你赢了!") elif player_choice == "3" and computer_choice == 2: print("你输了!") elif player_choice == "3" and computer_choice == 3: print("平局!") else: print("无效的选择。请重新输入。") play_again = input("是否继续游戏?(y/n): ").lower() if play_again!= "y": break
|