p ython打印猜拳游戏
时间: 2023-07-30 22:07:28 浏览: 98
好的,下面是一个 Python 打印猜拳游戏的示例代码:
```python
print("欢迎来到猜拳游戏!")
print("1.石头 2.剪刀 3.布")
player = input("请输入您的选择(1-3): ")
if player == "1":
print("您出了石头。")
elif player == "2":
print("您出了剪刀。")
elif player == "3":
print("您出了布。")
else:
print("输入无效,游戏结束。")
exit()
import random
computer = random.randint(1, 3)
if computer == 1:
print("电脑出了石头。")
elif computer == 2:
print("电脑出了剪刀。")
else:
print("电脑出了布。")
if player == "1" and computer == 2:
print("恭喜您,您赢了!")
elif player == "2" and computer == 3:
print("恭喜您,您赢了!")
elif player == "3" and computer == 1:
print("恭喜您,您赢了!")
elif player == computer:
print("平局!")
else:
print("很遗憾,您输了。")
```
这段代码实现了一个简单的猜拳游戏,玩家通过输入 1、2、3 分别代表石头、剪刀和布,与电脑进行猜拳,输出结果。
阅读全文