手机号数据统计:移动、联通、电信数量及非法号码分析
手机号数据统计
cm = 0 # 中国移动个数 cu = 0 # 中国联通个数 ct = 0 # 中国电信个数 lenerr = 0 # 长度不合法个数 digiterr = 0 # 字符不合法个数 preerr = 0 # 号段不合法个数
字段
phone_prefix = ['130','131','132','155','156','185','186','145','176', '134','135','136','137','138','139','147','150','151','152','157','158','159','178','182','183','184','187','188', '133','153','189']
with open('phone.txt','r') as file:
phone_list = file.readlines() # 读取数据
phone_list = list(set(phone_list)) # 数据去重
for phone_num in phone_list:
valid = True # 假设手机号合法
# 判断长度
if len(phone_num.strip()) != 11:
lenerr += 1
valid = False
# 判断字符
elif not phone_num.strip().isdigit():
digiterr += 1
valid = False
else:
# 判断号段
prefix = phone_num.strip()[:3]
if prefix in phone_prefix:
if prefix in ['130','131','132','155','156','185','186','145','176']:
cu += 1
elif prefix in ['134','135','136','137','138','139','147','150','151','152','157','158','159','178','182','183','184','187','188']:
cm += 1
elif prefix in ['133','153','189']:
ct += 1
else:
preerr += 1
valid = False
print('移动数量为%d个, 联通数量为%d个, 电信数量为%d个, 长度不合法数量为%d个, 字符不合法数量为%d个, 号段不合法数量为%d个。 ' % (cm, cu, ct,lenerr,digiterr,preerr))
原文地址: https://www.cveoy.top/t/topic/oct0 著作权归作者所有。请勿转载和采集!