Python randomly generates name + phone number + email

How to randomly generate name + phone number + email
Insert picture description here

First import the random library

First import random random library

import random as r

Design a method to generate random names

Next, design a method to generate random names

def name():
    # 随机姓名
    first_name = ["张", "曾", "李", "王", "刘", "赵", "蒋", "孟", "陈", "徐", "杨", "沈", "马", "高", "殷", "欧阳"]
    second_name = ["伟", "华", "建国", "洋", "刚", "万里", "爱民", "牧", "陆", "路", "昕", "鑫", "兵", "硕", "志宏", "峰", "磊", "雷", "文",
                   "明浩", "光", "超", "军", "达"]
    # name = r.choice(first_name) + r.choice(second_name)
    name = r.choice(first_name) + ''.join(r.choice(second_name))
    print('姓名:' + name)

A method to generate random phone numbers and email addresses

Writing a method to generate random phone number and email

def number_add_email():
    # 随机手机号
    prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
               "147", "150", "151", "152", "153", "155", "156", "157", "158", "159",
               "185", "187", "188", "189"]
    # print(random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8)))
    num1 = r.choice(prelist) + ''.join(r.choice('0123456789') for i in range(8))
    print('电话:'+num1)
    # 随机邮箱
    pre1 = ['@qq.com', "@163.com"]
    print('邮箱:'+num1 + ''.join(r.choice(pre1)))

run

Final execution

if __name__ == '__main__':
    name()
    number_add_email()

Process total code

import random as r


def name():
    # 随机姓名
    first_name = ["张", "曾", "李", "王", "刘", "赵", "蒋", "孟", "陈", "徐", "杨", "沈", "马", "高", "殷", "欧阳"]
    second_name = ["伟", "华", "建国", "洋", "刚", "万里", "爱民", "牧", "陆", "路", "昕", "鑫", "兵", "硕", "志宏", "峰", "磊", "雷", "文",
                   "明浩", "光", "超", "军", "达"]
    # name = r.choice(first_name) + r.choice(second_name)
    name = r.choice(first_name) + ''.join(r.choice(second_name))
    print('姓名:' + name)


def number_add_email():
    # 随机手机号
    prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
               "147", "150", "151", "152", "153", "155", "156", "157", "158", "159",
               "185", "187", "188", "189"]
    # print(random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8)))
    num1 = r.choice(prelist) + ''.join(r.choice('0123456789') for i in range(8))
    print('电话:'+num1)
    # 随机邮箱
    pre1 = ['@qq.com', "@163.com"]
    print('邮箱:'+num1 + ''.join(r.choice(pre1)))


if __name__ == '__main__':
    name()
    number_add_email()

Finally, the randomly generated format is as follows
: Name: ##
Phone: #¥%%! &
Mailbox: #¥%%! &@##.com

Guess you like

Origin blog.csdn.net/JasonZ227/article/details/111944135