写一个用python语言猜拳的脚本
时间: 2024-05-14 09:13:04 浏览: 35
猜拳的脚本
好的,下面是一个简单的猜拳游戏的Python脚本:
```python
import random
options = ['rock', 'paper', 'scissors']
while True:
player_choice = input('Please choose rock/paper/scissors, or type exit to quit: ').lower()
if player_choice == 'exit':
break
if player_choice not in options:
print('Invalid input, please try again!')
continue
computer_choice = random.choice(options)
print('You chose', player_choice)
print('Computer chose', computer_choice)
if player_choice == computer_choice:
print('It\'s a tie!')
elif (player_choice == 'rock' and computer_choice == 'scissors') or (player_choice == 'paper' and computer_choice == 'rock') or (player_choice == 'scissors' and computer_choice == 'paper'):
print('You win!')
else:
print('Computer wins!')
```
如果您有其他问题,欢迎继续提问。
阅读全文