Python 练习题:判断手机号码

手机验证码:我们在注册应用的时候常常使用手机号作为账户名,在短信验证之前一般都会检测号码的真实性,如果是不存在的号码就不会发送验证码。检验规则如下:

号码不低于11位;

时移动联通电信号段的一个号码;

号段如下:

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]

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']

phone_num=input('Enter Your number:')
num3=phone_num[-11:-8]
num4=phone_num[-11:-7]
def telephone():
    if len(phone_num)>=11:
        Mobile=num3 in CN_mobile or num4 in CN_mobile
        Union=num3 in CN_union or num4 in CN_union
        Telecom=num3 in CN_telecom or num4 in CN_telecom
        if Mobile :
            print('China Mobile')
            print('We are sending verification code via text to your phone:',phone_num)
        elif Union :
            print('China Union')
            print('We are sending verification code via text to your phone:',phone_num)
        elif Telecom :
            print('China Telecom')
            print('We are sending verification code via text to your phone:',phone_num)
        else :
            print('No such a oerater')
    else:
        print('Invalid length,your number should be in 11 digits')
telephone()
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值