Python-产生密码

#         1、写一个产生一批密码的程序,输入100,就产生100条密码
#         2、要求密码长度大于6,必须包含大写字母、小写字母、数字和特殊符号
#         3、每次产生的密码不能重复
#         4、写到文件里面

import random, string

password = input('请输入要产生多少条密码:').strip()
pwd = set()
password = int(password)
while len(pwd)!=password:
    p = pwd.add(''.join(random.sample(string.ascii_uppercase,2)+random.sample(string.ascii_lowercase,2)+random.sample(string.punctuation,2)
    +random.sample(string.digits,2))+'
')
with open('passwords.txt','a+')as fw:
    fw.writelines(pwd)
原文地址:https://www.cnblogs.com/brf-test/p/12681924.html