Python骰子猜大小游戏

2018-06-20  本文已影响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()
上一篇下一篇

猜你喜欢

热点阅读