Write a batch-generated account function in Python (user-controlled data length, number of data bars)

Source: Internet
Author: User

# 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.