2018-08-24 摇色子 - 小游戏

2018-08-24 摇色子 - 小游戏_第1张图片
image.png
import random

def RollDice(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 RollResult(total):
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return 'BIG'
    elif isSmall:
        return 'SMALL'

def start_game():
    print('<<<<>>>>')
    money = 1000
    choices = ['BIG', 'SMALL']
    while money != 0:
        your_Choice = input('BIG or SMALL:')
        while your_Choice not in choices:
            if your_Choice == 'E':
                exit()
            else:
                your_Choice = input('BIG or SMALL again:')
        your_bet = input('Your bet:')
        while int(your_bet) > money or int(your_bet) < 1:
            your_bet = input('Invalid bet, please bet again:')
        points = RollDice()
        total = sum(points)
        youwin = your_Choice == RollResult(total)
        if youwin:
            money = money + int(your_bet)
            print('your points is:', points, "You WIN",
                'Your money now is:', money)
        else:
            money = money - int(your_bet)
            print('your points is:', points, "You LOSE"),
            print('Your money now is:', money)
    print('No meney to bet now! You lose ALL')
    print('<<<<>>>>')
    exit()

start_game()

摇色子 - 小游戏 测试:


2018-08-24 摇色子 - 小游戏_第2张图片
image.png

你可能感兴趣的:(2018-08-24 摇色子 - 小游戏)