# -*- coding:utf-8 -*- import random list_Xing=['赵','钱','孙','李','周','吴','郑','王','冯','陈','褚','卫','蒋','沈','韩','杨','张','李'] list_Ming=['豫','章','故','郡','洪','都','新','府','星','分','翼','轸','地','接','衡','庐','襟','三','江','','而','带','五','湖','控','蛮','荆','而','引','瓯','越','物','华','天','宝','龙','光','射','牛','斗','之','墟','人','杰','地','灵','徐','孺','饯','子'] list_studentname=[] for i in range(5): name=random.choice(list_Xing)+random.choice(list_Ming)+random.choice(list_Ming) list_studentname.append(name) #将随机生成的五个姓名生成一个列表list_student for studentname in list_studentname: print studentname pass
上面写的代码太弱智了。下面代码简洁点
# -*- coding:utf-8 -*- import random xing='赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜' ming='豫章故郡洪都新府星分翼轸地接衡庐襟三江而带五湖' X=random.choice(xing) M="".join(random.choice(ming) for i in range(2)) print(X+M)
# -*- coding:utf-8 -*-
import random
xing='赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
ming='豫章故郡洪都新府星分翼轸地接衡庐襟三江而带五湖'
X=random.choice(xing)
M="".join(random.choice(ming) for i in range(2))
print(X+M)