请帮我用python写一个猜拳游戏
时间: 2023-08-31 16:13:26 浏览: 131
python猜拳游戏
好的,以下是一个简单的猜拳游戏的Python代码:
```python
import random
options = ['rock', 'paper', 'scissors']
while True:
player_choice = input("Enter your choice (rock/paper/scissors): ")
computer_choice = random.choice(options)
print(f"You chose {player_choice}, computer chose {computer_choice}.")
if player_choice == computer_choice:
print("It's a tie!")
elif player_choice == 'rock' and computer_choice == 'scissors':
print("You win!")
elif player_choice == 'paper' and computer_choice == 'rock':
print("You win!")
elif player_choice == 'scissors' and computer_choice == 'paper':
print("You win!")
else:
print("Computer wins!")
play_again = input("Do you want to play again? (y/n) ")
if play_again.lower() != 'y':
break
```
运行代码后,你将会被要求输入你的选择,然后计算机将随机生成一个选择并展示它。接下来,程序将检查谁赢了或是否平局,并询问你是否想要再玩一次。
阅读全文