# 1, write a function, batch generation of some registered use of the account: The resulting account is the end of @163.com, the length of the user input, the number of entries generated by the user input, the user name can not be repeated, the user name must be composed of uppercase letters, lowercase letters, numbers
Import random,string
def Users (Num,len):
result = []
A = String.ascii_lowercase
b = String.ascii_uppercase
c = string.digits
D = string.ascii_letters
Count = 0
While Count < num:
If Len > 2:
A1 = Random.choice (a)
B1 = Random.choice (b)
C1 = Random.choice (c)
D1 = random.sample (d,len-3)
D1.append (A1)
D1.append (B1)
D1.append (C1)
Random.shuffle (D1)
Users = '. Join (D1) + ' @163.com ' + ' \ n '
If users not in result:
Result.append (Users)
Count +=1
Else
Print (' Please enter a length greater than 2 ')
Break
With open (' Users.txt ', ' W ') as FW:
Fw.writelines (Result)
Users (1,3)
#用集合的方式实现
def USERS (Num,len):
result = []
All_str = string.ascii_letters + string.digits
Upp_str = String.ascii_uppercase
Low_str = String.ascii_lowercase
str = set (string.digits)
Count = 0
While Count < num:
If Len > 2:
res = random.sample (All_str,len)
If set (RES) & Set (UPP_STR) and set (RES) & Set (LOW_STR) and set (res) & STR:
user = '. Join (RES) + ' @163.com ' + ' \ n '
If user not in result:
Result.append (user)
Count +=1
Else
Print (' Please enter a length greater than 2! ‘)
Break
With open (' Users.txt ', ' W ') as FW:
Fw.writelines (Result)
USERS (3,3)
Write a batch-generated account function in Python (user-controlled data length, number of data bars)