目录

游戏一:

游戏二:

补充:——查询账号(号码)


游戏一:

游戏:摇骰子

游戏规则:游戏开始,玩家选择Big or Small ,选择完开始摇三个骰子计算总值,11<= total <= 18为大,3<= total <= 10为小,然后告诉玩家猜对/猜错

import randomdef roll_dice(numbers = 3, points = None):print('<<<<< ROOL THE DICE!')if points is None:points = []while numbers > 0:point = random.randrange(1, 7)points.append(point)numbers = numbers - 1return pointsdef roll_result(total):isBig = 11 <= total <= 18isSmall = 3 <= total <= 10if isBig:return 'Big'elif isSmall:return 'Small'def start_game():print('<<<<< GAME STARTS! >>>>>')choices = ['Big', 'Small']your_choice = input('Big or Small')if your_choice in choices:points = roll_dice()total = sum(points)youWin = your_choice == roll_result(total)if youWin:print('The points are ', points, 'You win !')else:print('The points are ', points, 'You lose !')else:print('Invalid Words')start_game()start_game()

输出:

<<<<< GAME STARTS! >>>>>
Big or SmallBig
<<<<< ROOL THE DICE!
The points are  [3, 5, 3] You win !

游戏二:

游戏:摇骰子下注金额与赔率

游戏规则:和上诉游戏一样的大小值

  • 初始金额为1000
  • 金额为0时游戏结束
  • 默认赔率是一倍,押对得到相应金额,错输掉相应金额。
import randomdef roll_dice(numbers = 3, points = None):print('<<<<< ROOL THE DICE!')if points is None:points = []while numbers > 0:point = random.randrange(1, 7)points.append(point)numbers = numbers - 1return pointsdef roll_result(total):isBig = 11 <= total <= 18isSmall = 3 <= total <= 10if isBig:return 'Big'elif isSmall:return 'Small'def start_game():print('<<<<< GAME STARTS! >>>>>')choices = ['Big', 'Small']money = 1000while money > 0:your_choice = input('Big or Small:')pay_money = int(input('How much you wanna bet?'))if your_choice in choices:points = roll_dice()total = sum(points)youWin = your_choice == roll_result(total)if youWin:money = money + pay_moneyprint('The points are ', points, 'You win !')print('You gained ' + str(pay_money) + 'you have ' + str(money) + 'now')else:money = money - pay_moneyprint('The points are ', points, 'You lose !')print('You lost '+ str(pay_money) +  'you have ' + str(money) + 'now' )else:print('Invalid Words')start_game()start_game()

输出:

<<<<< GAME STARTS! >>>>>
Big or Small:Big
How much you wanna bet?500
<<<<< ROOL THE DICE!
The points are  [6, 5, 1] You win !
You gained 500you have 1500now
Big or Small:Small
How much you wanna bet?1000
<<<<< ROOL THE DICE!
The points are  [4, 3, 4] You lose !
You lost 1000you have 500now
Big or Small:Big
How much you wanna bet?500
<<<<< ROOL THE DICE!
The points are  [3, 1, 4] You lose !
You lost 500you have 0now

Process finished with exit code 0

遇到问题:

问题:TypeError: unsupported operand type(s) for +: 'int' and 'str'

: pay_money = int(input('How much you wanna bet?'))

补充:——查询账号(号码)

规则:在注册游戏是,会使用手机作为账户名,在短信验证前会检验号码真实性,如果不存在号码就不会发送验证码,检验规则如下:

  • 长度不少于11
  • 是移动、联通、电信号码段中的一个电话号码
def phone():CN_mobile = \[134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 147, 178, 1705 ]CN_union = [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709]CN_telecom = [133, 153, 180, 181, 189, 177, 17700]your_number = input('Enter Your  number:')first_three = int(your_number[0:3])first_four = int(your_number[0:4])if len(your_number) >= 11:if first_three in CN_mobile or first_four in CN_mobile:print('Operator : Chine Mobile')print('We \' re sending verification code via text to your phone', your_number)elif first_three in CN_union or first_four in CN_union:print('Operator : Chine Union')print('We \' re sending verification code via text to your phone', your_number)elif first_three in CN_telecom or first_four in CN_telecom:print('Operator : Chine Telecom')print('We \' re sending verification code via text to your phone', your_number)else:print("Invalid length, your number shoule be in 11 digits")phone()phone()

输出

Enter Your  number:135555555555555555
Operator : Chine Mobile
We ' re sending verification code via text to your phone 135555555555555555

猜大小(python)相关推荐

  1. python经典小游戏-用Python设计一个经典小游戏:猜大小

    码农那点事儿 关注我们,一起学习进步 本文主要介绍如何用Python设计一个经典小游戏:猜大小. 游戏规则: 初始本金是1000元,默认赔率是1倍,赢了,获得一倍金额,输了,扣除1倍金额. 玩家选择下 ...

  2. python练手程序之猜大小

    #看了前面几个章节,对python最基础的语法有了一定了解.写个程序来验证一下 #程序名:猜大小 #按投骰子的规则来猜大小,用户有初始资金1000,每次下注一定金额,直至用户输光.赢够10000或主动 ...

  3. python猜大小游戏,Python实现的摇骰子猜大小功能小游戏示例

    搜索热词 本文实例讲述了Python实现的摇骰子猜大小功能小游戏.分享给大家供大家参考,具体如下: 最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下 ...

  4. python猜密码游戏规则_Python实现的摇骰子猜大小功能小游戏示例

    本文实例讲述了Python实现的摇骰子猜大小功能小游戏.分享给大家供大家参考,具体如下: 最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环 ...

  5. python游戏设计_Python设计一个猜大小游戏

    Python设计小游戏实例 本文主要介绍如何用Python设计一个经典小游戏:猜大小. 在这个游戏中,将用到前面我介绍过的所有内容:变量的使用.参数传递.函数设计.条件控制和循环等,做个整体的总结和复 ...

  6. python编写摇骰子游戏_Python实现的摇骰子猜大小功能小游戏示例

    本文实例讲述了Python实现的摇骰子猜大小功能小游戏.分享给大家供大家参考,具体如下: 最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环 ...

  7. python简单小游戏赌大小分析_用Python设计一个经典小游戏:猜大小

    原标题:用Python设计一个经典小游戏:猜大小 本文主要介绍如何用Python设计一个经典小游戏:猜大小. 游戏规则: 初始本金是1000元,默认赔率是1倍,赢了,获得一倍金额,输了,扣除1倍金额. ...

  8. python笔记:猜大小,随机数

    '''猜大小'''import random cs=3 answer=random.randint(1,10) while cs>0:temp=input('请输入一个数字:')shuzi=in ...

  9. python掷骰子猜大小

    完成猜大小游戏 规则如下: 投掷3个骰子,如果3个骰子之和小于10为小,大于等于10为大 步骤分解: 请用户输入大或小(用0,1代替) 投掷3个骰子,使用random库中的randint函数生成骰点大 ...

  10. Python入门综合试题:猜大小

    游戏规则 游戏开始,首先玩家选择押大小,选择完成后开始摇三个骰子计算总值,总值大于11小于18位大,总值大于3小于10位小,然后告诉玩家猜对或猜错的结果. 程序必要知识 a_list=[1,2,3] ...

最新文章

  1. 美团方法论,苦练基本功
  2. 终端连接mysql是出现error 2003_远程连接MySQL报错ERROR 2003解决办法
  3. QueueToStack
  4. 微信小程序开发教程(基础篇)8-数据绑定下
  5. python注入点查找_python注入点查找工具
  6. Thinkphp3.2整合微信支付
  7. JavaScript css3模拟简单的视频弹幕功能
  8. 01-eclipse打包运行程序总是报错java.lang.NoClassDefFoundError和ava.lang.ClassNotFoundException(打包原理)
  9. 一个用js写的接口http调试程序
  10. 《编码规范和测试方法——C/C++版》作业 ·007——C++引入MySQL给C的API并简单封装
  11. PTA-Python题库(浙大版Python程序设计教材对应练习) 题解索引
  12. 微信登录app提示服务器异常,微信登录异常怎么办?微信登录异常的原因以及解决方法...
  13. java软连接_硬链接和软连接
  14. Springboot+mybatis
  15. 扫码支付 (基于微信)
  16. Excel重复编号,1万个数据重复1到100编号
  17. java 求最大公因数_三种算法求最大公约数——Java实现 | 学步园
  18. 电子设计大赛-微电网模拟系统
  19. 【乱入】Uva11021麻球繁衍
  20. java对远程url地址进行访问并获取返回的数据

热门文章

  1. 防CC攻击 软件防火墙和WEB防火墙大比较
  2. 拓宽你的认知,优秀的人都掌握的40个经典思维模型「附全部模型PPT」
  3. ppt2016保存.html,PPT做完以后,按了保存就消失不见了,怎么找到原来的PPT?
  4. Compact Multi-Signatures for Smaller Blockchains代码解析
  5. 凸凹函数定义以及判断
  6. 平均年薪50万,学好python程序员到底有多吃香?
  7. 如何用python进行相关性分析_Python 相关性分析 显著性检验
  8. 曾经大肆其道的电商返利APP,其运营策略你真的清楚吗,一文带你读懂返利APP的竞品分析
  9. 【保研面经】人大信息学院,北航计算机学院,中科大大数据学院,南大计算机系
  10. axurerp出现错误报告_Windows 应用程序无法安装 事件查看器报错