# 1, the random characters randomly from all seven # 2, respectively, and then all the uppercase and lowercase letters, numbers, special characters on the intersection # 1, second idea # from uppercase upper_Case = 'AZ' lower_Case = ' az' = digits' 0-9 'pUC = '23 $ @ $ @ $' Import Random Import String NUM = the iNPUT ( ' Please enter the password to generate how many: ' ) .strip () passwords = [] IF num.isdigit () : NUM = int (NUM) the while len (Passwords) =! NUM: P1 = random.sample (string.ascii_letters string.digits + + string.punctuation,. 7) # randomly 7 Print (P1) IF set(p1) & set(string.ascii_lowercase) and set(p1) & set(string.ascii_uppercase) \ and set(p1) & set(string.digits) and set(p1) & set(string.punctuation): password = ''.join(p1)#把密码变成字符串 if password not in passwords: passwords.append(password) else: print('请输入数字') f = open('passwrods.txt','w') for p in passwords: f.write(p+'\n') f.close()