python不用记分的猜拳游戏
时间: 2023-05-26 13:05:07 浏览: 56
以下是一个简单的Python猜拳游戏,其中不需要计分:
```python
import random
print("欢迎来到猜拳游戏!")
hand_gesture = ["剪刀", "石头", "布"]
# 用列表来存储手势
while True:
computer = random.choice(hand_gesture)
# 让电脑随机选择手势
player = input("请出拳(剪刀/石头/布):")
if player not in hand_gesture:
print("输入有误,请重新输入。")
continue
print("电脑出了:", computer)
print("你出了:", player)
if player == computer:
print("平局!")
elif (player == "剪刀" and computer == "布") or \
(player == "石头" and computer == "剪刀") or \
(player == "布" and computer == "石头"):
# 使用条件语句判断胜负
print("你赢了!")
else:
print("电脑赢了!")
play_again = input("是否再来一局?(是/否)")
if play_again != "是":
break
print("游戏结束。")
```
程序运行后会提示用户出拳,用户可以输入“剪刀”、“石头”或“布”中的任意一种,然后程序会随机选择一个手势并判断胜负。最后,程序会询问用户是否再来一局,如果用户输入的不是“是”,游戏就结束。