python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤
2024-10-20 17:25:36
摇骰子游戏升级
此次更改增加下注功能,启动资金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()
最新文章
- Unity3D框架插件uFrame实践记录(二)
- 浅谈Excel开发:十一 针对64位Excel的插件的开发和部署
- Node 编程规范
- GRIDVIEW多行多列合并单元格(合并列)
- php用soap创建webservice
- php中intval()函数
- win7系统中任务计划程序的使用与查询
- jsp页面使用javascript添加页面元素示例代码
- codeforces C. Restore Graph
- RHEL7查看网卡配置命令ip addr show
- 使用Swing实现简易而不简单的文档编辑器
- Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)
- JMeter 插件 Json Path 解析HTTP响应JSON数据
- VBS 备份文件
- python 3.6.1 安装scrapy踩坑之旅
- 【Pthreads】Pipeline Model(Assembly Line)示例
- 目标检测技术演进:R-CNN、Fast R-CNN、Faster R-CNN
- 自然语言交流系统 phxnet团队 创新实训 个人博客 (十二)
- 99 Times--Kate Voegele
- JavaScript中的垃圾回收和内存泄漏