python缩写一个猜拳游戏
时间: 2023-07-04 20:11:52 浏览: 97
python实现一个猜拳游戏
好的,下面是一个简单的Python猜拳游戏:
```python
import random
while True:
player_choice = input("请出拳(剪刀、石头、布):")
computer_choice = random.choice(["剪刀", "石头", "布"])
print("你出了:%s,电脑出了:%s" % (player_choice, computer_choice))
if player_choice == computer_choice:
print("平局!")
elif (player_choice == "剪刀" and computer_choice == "布") or \
(player_choice == "石头" and computer_choice == "剪刀") or \
(player_choice == "布" and computer_choice == "石头"):
print("你赢了!")
else:
print("你输了!")
play_again = input("要再玩一局吗?(Y/N):")
if play_again.lower() != "y":
break
```
这个游戏会不断循环,直到玩家选择退出。在每一轮中,玩家会输入自己的出拳,电脑会随机出拳,并且比较双方的出拳来决定胜负。玩家可以选择再玩一局或者退出游戏。
阅读全文