[‘ user0 ‘, ‘user1’, ‘user2’, ‘user3’, ‘user4’, ‘user5’]. Please write the program cx5.py to do the following: (1) Create a random initial password composed of 6 digits for each user, and then save the user name and password in a dictionary, and output the dictionary; (2) Save the user name and password to the file user_inf.txt. Import random all_chars = ‘0123456789’ import random all_chars = ‘0123456789’ import random all_chars = ‘0123456789 User_pwd_dict = {}# empty dictionary for name in user_name:
PWD = "# password for I in range(6): PWD += random. Choice (all_chars)# Random. Choice (all_chars)# Random. Choice (all_chars)# This cannot be matched with the user_pwd_dict[name] = pwd# key
Print (” initial password assigned, dictionary data :”,user_pwd_dict)# print dictionary
Fid = open(‘user_inf.txt’,’wt’)# open document for name, PWD in user_pwd_dict. Items ():# set each pair of keys and values in the dictionary as a tuplex, And return these tuples in a list
FID. Write (name + ':' + PWD + '\n')#
Fid. Close ()# print(” username and password saved to user_inf.txt! ) numpy.random.choice(a, size=None, replace=True, p=None)
Replace :True = “replace” = “p”; False = “p” = “p”; replace:True = “p”; Corresponds to array A, represents the probability of each element in array A, default is to select each element with the same probability. The dictionary is a mutable container model, and can store objects of any type. Each key value pair of the dictionary is separated by a colon. Each key value pair is separated by a comma, and the whole dictionary is enclosed in curly braces {}. my_dict = {key1:value1, key2:value2}