目录
游戏一:
游戏:摇骰子
游戏规则:游戏开始,玩家选择Big or Small ,选择完开始摇三个骰子计算总值,11<= total <= 18为大,3<= total <= 10为小,然后告诉玩家猜对/猜错
import random
def 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 - 1
return points
def roll_result(total):
isBig = 11 <= total <= 18
isSmall = 3 <= total <= 10
if 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 random
def 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 - 1
return points
def roll_result(total):
isBig = 11 <= total <= 18
isSmall = 3 <= total <= 10
if isBig:
return 'Big'
elif isSmall:
return 'Small'
def start_game():
print('<<<<< GAME STARTS! >>>>>')
choices = ['Big', 'Small']
money = 1000
while 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_money
print('The points are ', points, 'You win !')
print('You gained ' + str(pay_money) + 'you have ' + str(money) + 'now')
else:
money = money - pay_money
print('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 0nowProcess 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