46.使用while、if来完成剪刀石头布程序,要求,当玩家连续3次获胜时才退出游戏,否则继续玩。
win_times = 0
while win_times <= 2:
player = int(input("请输入:剪刀(0) 石头(1) 布(2):")) # 玩家自己玩/人机大战
# player = random.randint(0, 2) # 机器大战
computer = random.randint(0, 2)
if ((player == 0) and (computer == 2) or (player == 1) and (computer == 0) or (player == 2) and (computer == 1)):
win_times += 1
print("获胜,太棒了!")
elif player == computer:
win_times = 0
print("平局,再来一局!")
else:
win_times = 0
print("输了,决战下!")