用python设计一个石头剪子布的功能
时间: 2024-04-29 08:25:20 浏览: 55
好的,我可以为您介绍一个简单的石头剪子布游戏的实现方法。您可以通过以下代码实现:
```python
import random
print("欢迎来到石头剪子布游戏!")
print("请出拳:石头(1),剪子(2),布(3)")
while True:
player = int(input("请输入您的选项:"))
if player not in [1, 2, 3]:
print("输入有误,请重新输入!")
continue
computer = random.randint(1, 3)
print("电脑出了%d" % computer)
if (player == 1 and computer == 2) or (player == 2 and computer == 3) or (player == 3 and computer == 1):
print("恭喜您获胜!")
elif player == computer:
print("平局!")
else:
print("很遗憾,您输了!")
print("请出拳:石头(1),剪子(2),布(3)")
```
希望这个小游戏能给您带来乐趣!
阅读全文