美文网首页
python -12-石头/剪刀/布

python -12-石头/剪刀/布

作者: hsiaojun | 来源:发表于2018-04-19 01:29 被阅读0次
    # 使用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("不要走,决战到天亮")
    

    相关文章

      网友评论

          本文标题:python -12-石头/剪刀/布

          本文链接:https://www.haomeiwen.com/subject/tfdikftx.html