python小游戏----猜大小
2017-10-13 17:44
274 查看
#!/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()
相关文章推荐
- python 小游戏之摇骰子猜大小
- python摇骰子猜大小的小游戏
- Python实现的摇骰子猜大小功能小游戏示例
- 四、python笔记之改进小游戏
- python 猜数小游戏
- python脚本小游戏,剪刀石头布.
- Python第07周:一个小游戏
- Python 猜数小游戏
- Python小游戏 井字棋(人机对战,玩家对战)
- python实现猜单词小游戏
- python开发_自己开发的一个小游戏
- python写的猜数字小游戏
- 初学python, 自己编的掷筛子小游戏
- 用python写的小游戏
- 首个python程序,一个猜数字的小游戏 ^0^
- python小游戏——猜数字2.0
- python小游戏-猜猜我正在想的数字是多少?
- 算术小游戏(python版)
- (5)Python笔记:使用pygame库制作打方块小游戏