猜大小(python)

猜大小(python),第1张

概述目录 游戏一:游戏二:补充:——查询账号(号码)游戏一:游戏:摇骰子游戏规则:游戏开始,玩家选择BigorSmall,选择完开始摇三个骰子计算总值,11<=total<=18为大,3<=total<=10为小,然后告诉玩家猜对/猜错importrandomdefroll_dice(numbers=3,points=None):print(

目录

 

游戏一:

游戏二:

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


游戏一:

游戏:摇骰子

游戏规则:游戏开始,玩家选择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 - 1    return pointsdef 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 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 - 1    return pointsdef 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 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)全部内容,希望文章能够帮你解决猜大小(python)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1188556.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存