1、写个一函数,这个函数的功能是,传入一个数字,产生N条手机号,产生的手机号不能重复。
[150,189,188,170,132,150,186]
def phone(500):
phone.txt
2、写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的手机号不能重复。
邮箱前面的长度是6-12之间,产生的邮箱必须包含大写字母、小写字母、数字和特殊字符
[163.com,qq.com,sina.com,126.com]
1、
def random_PhoneNumber(N): import random l = [] for i in range(N): s=[150,189,188,170,132,150,186] h=random.choice(s) eight=random.randint(10000000,99999999) p="{}{}".format(h,eight) if p not in l: l.append(p) else: i -= 1 m=set(l) phone = ‘\n‘.join(l) with open(‘phone.txt‘, ‘w+‘) as f: f.writelines(phone) return len(m)print(random_PhoneNumber(500))
2、
def random_email(N): import string import random m = [] l = [] l.append(string.digits) l.append(string.ascii_letters) l.append(string.punctuation) l=‘‘.join(l) i=0 while i < N: s = [‘@163.com‘,‘@qq.com‘,‘@sina.com‘,‘@126.com‘] h = random.choice(s) rang = random.randint(6,12) randomNumber = "".join(random.choice(l) for j in range(rang)) email = set(randomNumber) lowletters = set(string.ascii_lowercase) upperletters = set(string.ascii_uppercase) digits = set(string.digits) punctuation = set(string.punctuation) if email&lowletters and email&digits and email&punctuation and email&upperletters: p="{}{}".format(randomNumber,h) if p not in m: m.append(p) i += 1 n=set(m) phone = ‘\n‘.join(m) with open(‘email.txt‘, ‘w+‘) as f: f.writelines(phone) return len(n)print(random_email(500))
原文地址:https://www.cnblogs.com/arraon/p/10029856.html
时间: 2024-10-20 08:52:43