''' You need to write a function that generates a batch number of accounts registered for use. The end of the account is @ 163.com generated by the length of the user input, generate how many also entered by the user, the user name can not be repeated, the user name must consist of uppercase letters, lowercase letters, numbers ''' import string import random NUM = (INPUT (int " number of pieces of data that will be generated in: " )) # Generate the user name function DEF username (NUM): user = [] lenght = int (the INPUT ( " Please enter your user name length: " )) # Enter the user name length the while ! len (the User) = NUM: str1 = random.sample ((+ string.ascii_letters string.digits), lenght) # randomly generated username str2 = '' .join (str1) # username spliced into a string by the list IF str2 Not in User: # string deduplication user1 + str2 = " @ 163.com " + " \ n- " # string concatenation mailbox user.append (user1) # string in List return User # Username written to the external file DEF OpenFile (filename, the User): F = Open (filename, ' W ' , encoding = " UTF-. 8 " ) # open file f.writelines (User) # The file list writing row f.close () OpenFile ( ' a.txt ' , username (NUM)) # retrieval function