Python实现猜拳游戏(人机大战)
import random
while True:
# 游戏玩家
player = int(input("石头(1),剪刀(2),布(3),退出(0) 请选择: "))
if (player != 1) and (player != 2) and (player != 3) and (player != 0):
print("您输入的序号有误,请重新输入!!!")
continue
# 电脑玩家
computer = random.randint(1, 3)
if player == 0:
print("欢迎下次光临")
break
# 判断胜负
elif (player == 1 and computer == 2) \
or (player == 2 and computer == 3) \
or (player == 3 and computer == 1):
print("恭喜你胜利了 算你狠!!!")
elif player == computer:
print("平局了 不行再来 决战到天亮!!!")
else:
print("你不行 小子")