优客文库提供全面的范文格式和文档模板,包括申请书、合同、借据、证明、求职信等,助力您快速撰写专业文档。

用python写一个由无数个自己姓名生成的人像

来自 江苏省苏州市 的网友 时间: 热度:°C 加入收藏 我要投稿 点赞()
```python
import random

def generate_name():
first_name = ["张", "李", "王", "刘", "陈", "杨", "赵", "黄", "周", "吴"]
middle_name = ["伟", "芳", "娜", "敏", "静", "丽", "强", "磊", "洋", "艳"]
last_name = ["华", "飞", "鹏", "宇", "浩", "凯", "晨", "雪", "龙", "杰"]

return random.choice(first_name) + random.choice(middle_name) + random.choice(last_name)

def generate_portraits(num):
portraits = []
for _ in range(num):
name = generate_name()
portrait = f"姓名:{name}
年龄:{random.randint(18, 60)}
性别:{random.choice(['男', '女'])}
职业:{random.choice(['教师', '医生', '工程师', '律师', '公务员', '商人', '艺术家', '运动员'])}"
portraits.append(portrait)
return portraits

num = int(input("请输入生成人像的数量:"))
portraits = generate_portraits(num)
for portrait in portraits:
print(portrait)
print("----------")
```
221381
领取福利

微信扫码领取福利

微信扫码分享