编写代码实现剪刀、石头、布的猜拳游戏:玩家输入1、2、3表示剪刀、石头、布
时间: 2023-08-07 17:05:55 浏览: 185
好的,以下是Python代码实现:
```python
import random
def play_game():
print("Let's play rock-paper-scissors game!")
print("Enter 1 for Scissors, 2 for Rock, 3 for Paper")
player_choice = int(input("Your turn: "))
computer_choice = random.randint(1, 3)
if player_choice == computer_choice:
print("It's a tie!")
elif player_choice == 1 and computer_choice == 3:
print("You win! Scissors cut Paper.")
elif player_choice == 2 and computer_choice == 1:
print("You win! Rock smashes Scissors.")
elif player_choice == 3 and computer_choice == 2:
print("You win! Paper covers Rock.")
else:
print("You lose! Better luck next time.")
play_game()
```
使用random库生成计算机选项,然后比较玩家和计算机的选项,输出胜负结果。
阅读全文