手机号码校验篇
利用列表,将中国移动联通电信的号码开头分别写入
CN_mobile =[134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,148,1705]
CN_union =[130,131,132,155,156,185,186,145,176,1709]
CN_telecom =[133,153,180,181,189,177,1700]
def mian():
Your_number = input("Enter your number:")
# CN_CN = {
# "CN_mobile" : [134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 147, 148,1705],
# "CN_union" : [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709],
# "CN_telecom" : [133, 153, 180, 181, 189, 177, 1700]
# }
#prefix取出输入的电话号码的前3位
prefix = int(Your_number[:3])
if len(Your_number) != 11:
print("Invalid length,your number should be in 11 digits")
# elif not any(prefix in segment for segment in CN_CN.values()):
#通过prefix not in 判断输入的电话号码 属不属于上面的三个运营商
elif prefix not in CN_mobile+CN_union+CN_telecom:
print("No such an operator")
else:
if prefix in CN_union:
print("Operator :China Union")
elif prefix in CN_mobile:
print("Operator :China mobile")
elif prefix in CN_telecom:
print("Operator :China telecom")
print(f"We're sending veriSfication code via text to your phone :{Your_number}")
mian()
定义main函数,运用判断语句,对输入的电话号码进行判断,是否为正确的手机号码,以及其运营商是哪个,如果需要更具体的电话号码运营商,号码归属地,邮编等可以在网上搜寻网站,进行接口接收,这样就可以实时收到电话号码的具体信息。
填充用户假数据
#设计思路; ''' 父类:FakeUser 功能: 1.随机姓名: a.单名字 b.双名字 c.无所谓是什么反正 有个名字就行 2.随机性别 子类:SnsUser 功能: 1.随机数量的跟随者 a。 few b。 a lot ''' ln_path = 'D:/python练习/last_name.txt' fn_path = 'D:/python练习/first_name.txt' fn = [] ln1 = [] #单字名 ln2 = [] #双字名 with open(fn_path,'r') as f: for line in f.readline(): fn.append(line.split('\n')[0]) print(fn) with open(ln_path,'r') as f: for line in f.readline(): if len(line.split('\n')[0])==1: ln1.append(line.split('\n')[0]) else: ln2.append(line.split('\n')[0]) print(ln1) # print(ln1) # print('='*70)#分割线 # print(ln2) # import random class FakeUser: def fake_name(self,amount=1,one_word=False,two_word=False): n = 0 while n <= amount: if one_word: full_name = random.choice(fn)+random.choice(ln1) elif two_word: full_name = random.choice(fn)+random.choice(ln2) else: full_name = random.choice(fn)+random.choice(ln1+ln2) yield full_name n +=1 def fake_gender(self,amount=1): n = 0 while n <= amount: gender = random.choice(['男','女','未知']) yield gender n +=1 class SnsUser(FakeUser): def get_followers(self,amount=1,few=True,a_lot=False): global followers n = 0 while n <=amount: if few: followers = random.randrange(1,50) elif a_lot: followers = random.randrange(200,10000) yield followers n+=1 user_a = FakeUser() user_b = SnsUser() for name in user_a.fake_name(30): print(name) for gender in user_a.fake_gender(30): print(gender)
小夕还是个初学者,希望向各位大佬不断学习,不断进步,向大佬看齐