用python写一个猜拳小游戏
时间: 2023-12-07 19:49:37 浏览: 133
好的,以下是用 Python 写的一个猜拳小游戏,希望您喜欢!
```python
import random
print("欢迎来到猜拳游戏!")
print("请出拳:1-石头,2-剪刀,3-布")
while True:
player = int(input("请出拳:"))
if player == 1:
print("你出拳:石头")
elif player == 2:
print("你出拳:剪刀")
elif player == 3:
print("你出拳:布")
else:
print("输入有误,请重新输入!")
continue
computer = random.randint(1, 3)
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("很遗憾,电脑赢了!")
again = input("再来一局?(y/n)").lower()
if again == 'y':
continue
else:
print("游戏结束,再见!")
break
```
好了,这就是猜拳小游戏的 Python 代码,您可以直接运行并玩一玩。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)