标签:
最近看一个python的教学视频,视频里面有一个文本,一堆帐号,电话号码啥的,于是写个python脚本
让这些数据自动生成
#coding:utf-8 import random def stringList(): str1 = [] str3 = [] for i in range(97, 123): str1.append(chr(i)) str2 = ‘‘.join(str1) for i in range(65, 91): str3.append(chr(i)) str4 = ‘‘.join(str3) strall = str2 + str4 return strall n = int(input("Please input u number :").strip()) ‘‘‘ def idList(): x = 0 x += 1 return x ‘‘‘ def nameList(): a = random.randint(3,5) name = ‘‘.join(random.sample(stringList(), a)) return name def dePartment(): list1 = [‘IT‘, ‘caiwu‘, ‘xiaoshou‘] dpt = random.choice(list1) return dpt def phoneList(): num = ‘0123456789‘ phone = ‘‘.join(random.choice(num) for i in range(11)) return phone print(‘id name department phone‘) for i in range(0, n): i += 1 print(‘%-5s %-8s %-13s %s‘ % (i, nameList(), dePartment(), phoneList()))
输出结果如下
END!
标签:
原文地址:http://www.cnblogs.com/changbo/p/5640022.html