python猜拳游戏
时间: 2023-06-28 07:07:47 浏览: 102
好的,下面是一个简单的 Python 猜拳游戏代码:
```python
import random
print("欢迎来到猜拳游戏!")
print("请出拳:1.石头 2.剪刀 3.布")
while True:
player = int(input("请输入你的选择(1-3):"))
computer = random.randint(1, 3)
if player == 1:
print("你出了石头")
elif player == 2:
print("你出了剪刀")
elif player == 3:
print("你出了布")
else:
print("无效的选择,请重新输入!")
continue
if computer == 1:
print("电脑出了石头")
elif computer == 2:
print("电脑出了剪刀")
elif computer == 3:
print("电脑出了布")
if player == computer:
print("平局!")
elif (player == 1 and computer == 2) or (player == 2 and computer == 3) or (player == 3 and computer == 1):
print("你赢了!")
else:
print("电脑赢了!")
play_again = input("是否继续游戏?(Y/N)")
if play_again == 'N' or play_again == 'n':
break
```
运行上面的代码,你可以开始和电脑玩猜拳游戏了。祝你好运!
阅读全文