猜拳游戏

import random
print('*'*20)
print("***欢迎来到猜拳游戏***
"
      "提示(请输入数字)
"
      "1(石头),2(剪刀),3(布),0(退出游戏)
"
      "赢一局得3分,输一局扣3分,平局不得分
")
y = 0
p = 0
s = 0
f = 0
while True:
    play = input("请出拳:")
    computer = random.randint(1, 3)
    res = play.isdigit()
    if res == True:
        player = int(play)
        if player <= 3 and player >=0:
            if  (computer==1 and player==2)  or (computer==2 and player==3)  or  (computer==3 and player==1):
                print("你输了,请再接再厉")
                s += 1
            elif computer == player:
                print("平局")
                p += 1
            elif player == 0:
                break
            else:
                print("你赢了!请继续加油")
                y += 1
        else:
            print("输入错误,请重新输入!"
                  "提示:"
                  "1(石头),2(剪刀),3(布),0(退出游戏)")
    else:
        print("输入错误,请输入数字")
    f = y*3 - s*3
    print("你赢了%d局,输了%d局,平局%d,共计得分%s"%(y,s,p,f))

  

原文地址:https://www.cnblogs.com/twoo/p/11651866.html