[‘ 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 Dict = {}# dict for name in user_name: PWD = "# dict for I in range(6): PWD += random. Choice (all_chars)# Random. Choice (all_chars)# Random. Choice (all_chars)# Dict [name] = pwd# print(" initial password assigned, Dict = ",user_pwd_dict)# print dictionary FID = open('user_inf.txt','wt')# write mode on Windows For name, PWD in user_pwd_dict. Items ():# Create a tuple for each pair of keys and values in the dictionary, Write (name + ':' + PWD + '\n')# fid. Close ()# print(" User name and password have been saved to user_inf.txt!" )
numpy.random.choice(a, size=None, replace=True, p=None)
Random numbers are drawn from A (as long as it is NDARRAY, but must be one-dimensional) and formed into an array of the specified size
Replace :True means you can take the same number, False means you can’t take the same number
Array p: corresponds to array a, and represents the probability of selecting each element in array a. The 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}