script01

import re, random, string

count1 = int(input('请输入密码个数(必须大于0): '))
i = 0
passwds = []
while i < count1:
        tmp = random.sample(string.ascii_letters + string.digits, 10)
        passwd = ''.join(tmp)
        if re.search('[0-9]', passwd) and re.search('[A-Z]', passwd) and re.search('[a-z]', passwd):
                passwds.append(passwd)
                i += 1
print(passwds)

script02

import string
import random

password_length = 16

def password_gen():
        l = []
        password = []
        dic = {
                0: string.digits,
                1: string.ascii_lowercase,
                2: string.ascii_uppercase,
                3: string.punctuation
        }

        while len(set(l)) < len(dic):
                l.clear()
                for _ in range(password_length):
                        l.append(random.randrange(0, len(dic)))
        for x in l:
                password.append(dic[x][random.randrange(0, len(dic[x]))])
        return ''.join(password)

print(password_gen())