python123+模拟卷C综合应用题+随机密码


AC代码展示


import random
random.seed(0x1010)
s="abcdefghijklmnopqrstuvwxyzABCDEFGH\
    IJKLMNOPQRSTUVWXYZ1234567890!@#$%^&* "
ls=[]#保存生成的随机密码,字符串列表
excludes=""
while len(ls)<10:#密码个数小于10
    pkw="" #pseudo keyword
    while True:
        pkw+=s[random.randint(0,len(s)-1)]
        if pkw[0] not in excludes:
            break
        pkw=""
    for i in range(9):
        pkw+=s[random.randint(0,len(s)-1)]
    ls.append(pkw)
    excludes+=pkw[0]
fo=open("随机密码.txt","w",encoding="utf-8")
fo.write("\n".join(ls))
fo.close()

你可能感兴趣的:(python二级)