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()

你可能感兴趣的:(python,开发语言)