python演练--石头剪刀布游戏源码

自己编写,还请指正

 import  random
    import time
    win_list=[("石头","剪刀"),("布","石头"),("剪刀","布")]
    kind_list=['石头','剪刀','布']
    chart = {"张旭阳":"123456","程武飞":"456789","王少东":"123789"}
    def yonghuming():
     count=3
     while True:
        name = input("请输入用户名:")
        if name in chart:
            print("用户名正确")
            return name
            break
        else:
            if count==1:
                print("你登个锤子")
                exit()
            count -= 1
            print("请输入正确用户名,你还有%d次机会" % count)
    def mima(name):
     count1=3
     while True:
        password = input("请输入用户名密码:")
        if chart[name] == password:
            print("欢迎进入人机大战")
            renji(name)
            break
        else:
            if count1==1:
                print("你玩个锤子")
                exit()
            count1 -=1
            print("密码错误,你还有%d次机会" % count1)
    def renji(name):
     count=3
     print("===================%s,欢迎来到人机大战=========================" % name)
     while True:
        print("请等待机器人出拳。。。")
        time.sleep(1)
        print("...")
        time.sleep(1)
        robot=random.choice(kind_list)
        print("机器人已出拳")
        people=str(input("请你输入石头/剪刀/布:").strip())
        time.sleep(1)
        if people in kind_list:
            print("您输入的是:",people)
            time.sleep(1)
            print("机器人输入的是",robot)
            if people == robot:
                if count==1:
                    print("game over,请续费")
                    exit()
                count -= 1
                print("平局,你还有%d次机会" % count)
            elif (people,robot) in win_list:
                print("恭喜你,你赢了")
                break
            else:
                if count==1:
                    print("game over,请续费")
                    exit()
                count -= 1
                print("你输了,小垃圾,你还有%d次机会" % count)
    
        else:
            if count == 1:
                print("game over,请续费")
                exit()
            count -= 1
            print("别瞎输入!你还有%d次机会"  % count)
    
    
    name=yonghuming()
    mima(name)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值