帮我用Python写个猜拳程序
时间: 2023-05-13 20:05:42 浏览: 132
当然可以,以下是一个简单的猜拳程序的 Python 代码:
```python
import random
print("欢迎来到猜拳游戏!")
print("请出拳:1.石头 2.剪刀 3.布")
while True:
player = int(input("请输入你的选择(1-3):"))
computer = random.randint(1, 3)
if player == 1:
if computer == 1:
print("平局!")
elif computer == 2:
print("你赢了!")
else:
print("你输了!")
elif player == 2:
if computer == 1:
print("你输了!")
elif computer == 2:
print("平局!")
else:
print("你赢了!")
elif player == 3:
if computer == 1:
print("你赢了!")
elif computer == 2:
print("你输了!")
else:
print("平局!")
else:
print("输入错误,请重新输入!")
```
希望这个程序能够帮助你玩得开心!
阅读全文