python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤
摇骰子游戏升级
此次更改增加下注功能,启动资金1000元,每次赔率都是一倍,钱输光退出。
源码:
#!/user/bin/env python
#-*-coding:utf-8 -*-
#Author: qinjiaxi
import random
#一次摇三个骰子并将结果存在列表中
def role_a_dice(number = 3, point = None ):
print('Let\'s play a game')
if point is None:
point = []
while number > 0:
point.append(random.randint(1, 6))
number -= 1
return point
#将结果转换成'大小'字符串
def dice_reslut(total):
isBig = 11 <= total <= 18
isSmall = 3 <= total <= 10
if isBig:
return "Big"
if isSmall:
return "Small"
def start_game(money = 1000):
while money > 0:
print("-----GAME START-----")
choices = ['Big', 'Small']
U_choices = input('pls enter your choice:')
if U_choices in choices:
money_choice = int(input('How much you wanna bet ? -'))
points = role_a_dice()#调用函数摇骰子得到三个骰子的结果
totals = sum(points)#三次结果相加得到最终点数
resluts = dice_reslut(totals)#调用函数得到将最终点数转换成字符串
if U_choices == resluts:
print('点数是:{}恭喜你猜对了'.format(points))
money += money_choice
print('you gain {}, you have:{} now'.format(money_choice,money))
else:
print('点数是:{}抱歉猜错了'.format(points))
money -= money_choice
print('you lost {}, you have:{} now'.format(money_choice, money))
else:
print('Invalid words.')
start_game()
else:
print('GAME OVER')
start_game()
三大运营商短信验证过滤
如果是三个运行商里的号码就发短信,号码不足11位提示
源码:
!/user/bin/env python
#-*-coding:utf-8 -*-
#Author: qinjiaxi def verificate_number():
while True:
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,1700]
number = input('pls enter your number:')
first_three = int(number[0:3])
first_four = int(number[0:4])
if len(number) == 11:
if first_four in CN_mobile or first_three in CN_mobile:
print('operator is china mobile' )
print('we\'re sending verification code via text to your phone {}'.format(number))
break
elif first_four in CN_union or first_three in CN_union:
print('operator is china union')
print('we\'re sending verification code via text to your phone {}'.format(number))
break
elif first_four in CN_telecom or first_three in CN_telecom:
print('operator is china telecom')
print('we\'re sending verification code via text to your phone {}'.format(number))
break
else:
print('No such a operator')
else:
print('Invalid length, your number should be in 11 digits')
verificate_number()
python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤的更多相关文章
- python实现简单投资复利函数以及实现摇骰子猜大小函数
复利函数: #!/user/bin/env python #-*-coding:utf-8 -*- #Author: qinjiaxi def invest(amount, rate, time): ...
- python 小游戏之摇骰子猜大小
最近学习Python的随机数,逻辑判断,循环的用法,就想找一些练习题,比如小游戏猜大小,程序思路如下: 开发环境:python2.7 , 附上源代码如下: 摇骰子的函数,这个函数其实并不需要传任何参数 ...
- python摇骰子猜大小的小游戏
#小游戏,摇筛子押大小的小游戏玩家初始有1000块钱,可以压大压小作为赌注 import random #定义摇筛子的函数: def roll_dice(number = 3,points = Non ...
- python基于LeanCloud的短信验证
python基于LeanCloud的短信验证 1. 获取LeanCloud的Id.Key 2. 安装Flask框架和Requests库 pip install flask pip install re ...
- 注册登录页面修订-Python使用redis-手机验证接口-发送短信验证
登录页面修订 views.Login.vue <template> <div class="login box"> <img src="@/ ...
- python数据挖掘第三篇-垃圾短信文本分类
数据挖掘第三篇-文本分类 文本分类总体上包括8个步骤.数据探索分析->数据抽取->文本预处理->分词->去除停用词->文本向量化表示->分类器->模型评估.重 ...
- [Python学习之路] 猜大小游戏
# coding =utf-8 import random def roll_dice(number=3, points=None): if points == None: points = [] w ...
- 用Python免费发短信,实现程序实时报警
进入正文 今天跟大家分享的主题是利用python库twilio来免费发送短信. 先放一张成品图: 代码放在了本文最后的地址中 正文 眼尖的小伙伴已经发现了上面的短信的前缀显示这个短信来自于一个叫Twi ...
- 使用 Python 发送短信?
上回食行生鲜签到,我们说到怎么把签到结果发出来,于是就找到了 Twilio. Twilio 是一个位于加利福尼亚的云通信(PaaS)公司,致力于为开发者提供通讯模块的 API.由于 Twilio 为试 ...
随机推荐
- Java 网络编程 -- 基于TCP实现文件上传
Java TCP 操作基本流程 一.创建服务器 1.指定端口, 使用serverSocket创建服务器 2.阻塞式连接 accept 3.操作:输入流 输出流 4.释放资源 二.创建客户端 1.使用S ...
- 集合-ArrayList 源码解析
ArrayList是一种以数组实现的List,与数组相比,它具有动态扩展的能力,因此也可称之为动态数组. 类图 ArrayList实现了List, RandomAccess, Cloneable, j ...
- 如何让ThreadPoolExecutor更早地创建非核心线程
最近在项目中遇到一个需要用线程池来处理任务的需求,于是我用ThreadPoolExecutor来实现,但是在实现过程中我发现提交大量任务时它的处理逻辑是这样的(提交任务还有一个submit方法内部也调 ...
- python实现线性回归之简单回归
代码来源:https://github.com/eriklindernoren/ML-From-Scratch 首先定义一个基本的回归类,作为各种回归方法的基类: class Regression(o ...
- Test Test...
标题: Test(一级标题) Test(二级标题) Test(三级标题) 列表: test(列表) Alpha Beta Gamma test 2 Delte Epsilon 链接: 点兔成金斐波那契 ...
- fedora 21下Virtual Box安装Windows XP SP3
Installing Virtual Box and Windows XP SP3 during Fedora 21 The first step:Download and Install Virtu ...
- js 之 箭头函数 (未学完)
js之箭头函数表达式 箭头函数表达式的语法比函数表达式更短,并且没有自己的this,arguments,super或 new.target.这些函数表达式更适用于那些本来需要匿名函数的地方,并且它们不 ...
- 【Linux网络基础】上网原理流程
1. 局域网用户上网原理 上网过程说明: 确保物理设备和线路架构准备完毕,并且线路通讯状态良好 终端设备需要获取或配置上局域网(私有地址)地址,作为局域网网络标识 当终端设备想上网时,首先确认访问的地 ...
- 前端存储 (5) - service worker 离线存储
service worker 离线存储 简介: 一般的网站 在我们无法访问的 时候 一般 回出现 如下 该网页无法访问 service worker 构建的网站不会出现这个错误,因为所有的 请求都是先 ...
- JAVA_WEB--jsp语法
JSP声明 一个声明语句可以声明一个或多个变量.方法,供后面的Java代码使用.在JSP文件中,必须先声明这些变量和方法然后才能使用它们. JSP声明的语法格式: <%! declaration ...