zoukankan      html  css  js  c++  java
  • python随机产生手机号和邮箱号

    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))
  • 相关阅读:
    vue2-highcharts 动态加载数据
    css选择器易混符号(~波浪号、+加号、>大于号)
    前端压缩字体文件---成功
    数组里添加一行数据(splice)
    new Date(date).getTime()不兼容iphone
    关于表单验证的正则表达式
    vuejs+webpack环境搭建
    Bootstrap弹出层(modal)垂直居中简单解决方案(无需修改js)
    $.get、$.post、$getJSON、$ajax的用法跟区别
    流式布局- 流式图片
  • 原文地址:https://www.cnblogs.com/arraon/p/10029856.html
Copyright © 2011-2022 走看看