用python帮我写一个猜拳小游戏
时间: 2023-12-07 09:01:11 浏览: 109
好的,我可以为您编写一个猜拳小游戏。以下是代码:
```
import random
print("欢迎来到猜拳游戏!")
print("请出拳:1-石头,2-剪刀,3-布")
player_choice = int(input())
if player_choice == 1:
print("你出了石头!")
elif player_choice == 2:
print("你出了剪刀!")
elif player_choice == 3:
print("你出了布!")
else:
print("无效的选择,请重新开始!")
computer_choice = random.randint(1,3)
if computer_choice == 1:
print("电脑出了石头!")
elif computer_choice == 2:
print("电脑出了剪刀!")
else:
print("电脑出了布!")
if player_choice == 1 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 == computer_choice:
print("平局!")
else:
print("电脑赢了!")
```
祝您玩得愉快!现在,您可以继续向我提问。
阅读全文