python -12-石头/剪刀/布

2018-04-19  本文已影响0人  hsiaojun
# 使用while、if来完成剪刀石头布程序,要求,当玩家第3次获胜时才退出游戏,否则继续玩

先设定赢的次数,再while循环 ,循环下面input,不然死循环

import random

win_times = 0
while win_times <= 2:
    player = int(input("请输入:剪刀(0) 石头(1) 布(2)"))
    computer = random.randint(0, 2)

    if (player == 0 and computer == 2) or (player == 1 and computer == 0) or (player == 2 and computer == 1):
        print("玩家胜利")
        win_times += 1
    elif player == computer:
        print("平局")
    else:
        print("不要走,决战到天亮")
上一篇下一篇

猜你喜欢

热点阅读