帮我写一个猜拳游戏.py
时间: 2023-04-04 08:04:26 浏览: 115
基于java开发的项目源码资源,91-猜拳游戏.rar
好的,我可以帮你写一个猜拳游戏.py。以下是代码:
import random
print("欢迎来到猜拳游戏!")
print("请出拳:1.剪刀 2.石头 3.布")
while True:
player = int(input("请出拳:"))
computer = random.randint(1, 3)
if player == 1:
if computer == 1:
print("平局!")
elif computer == 2:
print("你输了!")
else:
print("你赢了!")
elif player == 2:
if computer == 1:
print("你赢了!")
elif computer == 2:
print("平局!")
else:
print("你输了!")
elif player == 3:
if computer == 1:
print("你输了!")
elif computer == 2:
print("你赢了!")
else:
print("平局!")
else:
print("请输入正确的数字!")
play_again = input("再玩一局?(y/n)")
if play_again.lower() != "y":
break
希望你喜欢这个猜拳游戏.py!
阅读全文