python之猜拳小游戏,三局两胜

1、用while循环写

import random
print("这是一个猜拳游戏,三局两胜")
print("剪刀(0)石头(1) 布(2)")
win = 0
lose = 0
while win<2 and lose<2:
    player = int(input("请输入:剪刀(0)  石头(1)   布(2):"))
    my = random.randint(0,2)
    print("我出的是%d" %my)
    if player == 0 and  my==2 or player ==1 and my ==0 or player==2 and my==0:
        print("你赢了")
        win+=1
    elif player == my:
        print("平局")
    else:
        print("你输了")
        lose+=1
    if win<2 and lose<2:
        print("再来")
    elif win==2:
        print("游戏结束,你赢了")
    elif lose==2:
        print("游戏结束,你输了")
    else:
        print("游戏结束,平局")

你可能感兴趣的:(study,python)