Python随机生成姓名+电话号码+邮箱
程序员文章站
2024-01-03 23:39:10
怎么样生成随机姓名和电话号码和邮箱?首先导入随机库设计一个生成随机姓名的方法一个生成随机手机号与邮箱的方法运行过程总代码如何随机生成姓名+电话号码+邮箱首先导入随机库首先导入random随机库import random as r设计一个生成随机姓名的方法接下设计一个生成随机姓名的方法def name(): # 随机姓名 first_name = ["张", "曾", "李", "王", "刘", "赵", "蒋", "孟", "陈", "徐", "杨", "沈", "马",...
怎么样生成随机姓名和电话号码和邮箱?
如何随机生成姓名+电话号码+邮箱
首先导入随机库
首先导入random随机库
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()
过程总代码
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()
最后得到随机生成的格式如下
姓名:##
电话:#¥%%!&
邮箱:#¥%%!&@##.com
本文地址:https://blog.csdn.net/JasonZ227/article/details/111944135