python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤

Posted 秦朗的天空

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤相关的知识,希望对你有一定的参考价值。

摇骰子游戏升级

此次更改增加下注功能,启动资金1000元,每次赔率都是一倍,钱输光退出。

源码:

 1 #!/user/bin/env python
 2 #-*-coding:utf-8 -*-
 3 #Author: qinjiaxi
 4 import random
 5 #一次摇三个骰子并将结果存在列表中
 6 def role_a_dice(number = 3, point = None ):
 7     print(Let‘s play a game)
 8     if point is None:
 9         point = []
10     while number > 0:
11         point.append(random.randint(1, 6))
12         number -= 1
13     return point
14 #将结果转换成‘大小‘字符串
15 def dice_reslut(total):
16     isBig = 11 <= total <= 18
17     isSmall = 3 <= total <= 10
18     if isBig:
19         return "Big"
20     if isSmall:
21         return  "Small"
22 def start_game(money = 1000):
23     while money > 0:
24         print("-----GAME START-----")
25         choices = [Big, Small]
26         U_choices = input(pls enter your choice:)
27         if U_choices in choices:
28             money_choice = int(input(How much you wanna bet ? -))
29             points = role_a_dice()#调用函数摇骰子得到三个骰子的结果
30             totals = sum(points)#三次结果相加得到最终点数
31             resluts = dice_reslut(totals)#调用函数得到将最终点数转换成字符串
32             if U_choices == resluts:
33                 print(点数是:{}恭喜你猜对了.format(points))
34                 money += money_choice
35                 print(you gain {}, you have:{} now.format(money_choice,money))
36             else:
37                 print(点数是:{}抱歉猜错了.format(points))
38                 money -= money_choice
39                 print(you lost {}, you have:{} now.format(money_choice, money))
40         else:
41             print(Invalid words.)
42             start_game()
43     else:
44         print(GAME OVER)
45 start_game()

三大运营商短信验证过滤

如果是三个运行商里的号码就发短信,号码不足11位提示

源码:

 1 !/user/bin/env python
 2 #-*-coding:utf-8 -*-
 3 #Author: qinjiaxi
 4 
 5 def verificate_number():
 6     while True:
 7         CN_mobile =[134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705]
 8         CN_union = [130,131,132,155,156,185,186,145,176,1709]
 9         CN_telecom = [133,153,180,181,189,177,1700]
10         number = input(pls enter your number:)
11         first_three = int(number[0:3])
12         first_four = int(number[0:4])
13         if len(number) == 11:
14             if first_four in CN_mobile or first_three in CN_mobile:
15                 print(operator is china mobile )
16                 print(we‘re sending verification code via text to your phone {}.format(number))
17                 break
18             elif first_four in CN_union or first_three in CN_union:
19                 print(operator is china union)
20                 print(we‘re sending verification code via text to your phone {}.format(number))
21                 break
22             elif first_four in CN_telecom or first_three in CN_telecom:
23                 print(operator is china telecom)
24                 print(we‘re sending verification code via text to your phone {}.format(number))
25                 break
26             else:
27                 print(No such a operator)
28         else:
29             print(Invalid length, your number should be in 11 digits)
30 verificate_number()

 

以上是关于python实现摇骰子猜大小函数升级没把加注及三大运行商短信验证过滤的主要内容,如果未能解决你的问题,请参考以下文章

python摇骰子猜大小的小游戏

Python-使用tkinter实现的摇骰子小游戏

# python实现CRAPS赌博游戏(摇骰子)

用python编一个扔骰子猜大小的游戏,要求三局两胜制

python掷骰子游戏

Python小游戏小程序