美文网首页
Python骰子猜大小游戏

Python骰子猜大小游戏

作者: 獨孤記憶 | 来源:发表于2018-06-20 21:53 被阅读0次
    import random
    
    def roll(numbers = 3,points = None):
        print("开始游戏")
        if points is None :
            points = []
    
        while numbers > 0 :
            point =random.randrange(1,7)
            points.append(point)
            numbers = numbers-1
    
        return points
    
    def roll_set(total):
        isBig = 11 <= total <=18
        isSmall = 3 <= total <= 10
        if isBig:
            return 'Big'
    
        elif isSmall:
            return 'Small'
    
    def startgame():
        Havemoney = 1000
        while Havemoney > 0 :
            print('<<<<<<Game Starts !!!>>>>>>')
            choice = ['Big','Small']
            yourchoice = input('Big or Small :')
    
    
            if yourchoice in choice :
                yourbet = int(input(' 你打算玩几块钱的? :'))
                points = roll()
                total = sum(points)
                youwin = yourchoice == roll_set(total)
                
                if Havemoney- yourbet < 0 :
                    print('你没有那么多钱,请重新输入')
                    startgame()
                else :
                    pass
    
                if youwin :
                    print('骰子为',points,'好吧你赢了')
                    Havemoney = Havemoney+yourbet
                    print('你还有%d元!'%Havemoney)
                else :
                    print('骰子为',points,'你输了,继续努力!')
                    Havemoney = Havemoney - yourbet
                    print('你还剩%d元,下把搏一搏,单车变摩托'%Havemoney)
                    
            else:
                print('输入的指令有错,请重新输入')
    
        else :
            print('游戏结束!!!')
    
    startgame()

    相关文章

      网友评论

          本文标题:Python骰子猜大小游戏

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