python小游戏----猜大小

#!/user/bin/env python
# -*- coding:utf-8 -*-
import random


def roll_dice(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_result(total):
    isBig = 11 <= total <= 18
    isSmall = 3 <= total <= 10
    if isBig:
        return '大'
    elif isSmall:
        return '小'


def start_game():
    your_money = 1000
    while your_money > 0:
        print('----- 游戏开始 -----')
        choices = ['大', '小']
        your_choice = raw_input('请下注,大 or 小:')   #这个位置如果用input函数时输入的字符串要带引号
        your_bet = input('下注金额:')
        if your_choice in choices:
            points = roll_dice()
            total = sum(points)
            youWin = your_choice == roll_result(total)
            if youWin:
                print('骰子点数:', points)
                print('恭喜,你赢了 {} 元,你现在有 {} 元本金'.format(your_bet, your_money + int(your_bet)))
                your_money = your_money + int(your_bet)
            else:
                print('骰子点数:', points)
                print('很遗憾,你输了 {} 元,你现在有 {} 元本金'.format(your_bet, your_money - int(your_bet)))
                your_money = your_money - int(your_bet)
        else:
            print('格式有误,请重新输入')
    else:
        print('游戏结束')


start_game()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值