欢迎来到无荨的博客

想一千次,不如去做一次。如果自己不努力,那么这一辈子只可能在原地踏步!

猜拳游戏

import random
print('*'*20)
print("***欢迎来到猜拳游戏***\n"
      "提示(请输入数字)\n"
      "1(石头),2(剪刀),3(布),0(退出游戏)\n"
      "赢一局得3分,输一局扣3分,平局不得分\n")
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))

  

posted @ 2019-12-09 11:37  无荨  阅读(196)  评论(0编辑  收藏  举报