Python专栏 | 大题精讲:利用random库生成随机密码
作者:互联网
题目如下:
======================================================================
#第一步到第六步慢慢产生的结果
import random
#random.seed(0X1010)#做后面的题时要把这个注释掉不然总生成一样的
zi_fu = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*"
mi_ma =""
mi_ma_lie_biao=[]
chu_xian =""
while len(mi_ma_lie_biao)<10:
mi_ma=""
for i in range(0,10):
mi_ma+=zi_fu[random.randint(0,(len(zi_fu)-1))]
if mi_ma[0] in chu_xian:
continue
else:
mi_ma_lie_biao.append(mi_ma)
chu_xian += mi_ma[0]
file =open("随机密码.txt","w",encoding = "utf-8")
for i in range(10):
file.write(mi_ma_lie_biao[i]+"\n")
file.close()
标签:lie,ma,Python,精讲,random,mi,biao,seed 来源: https://blog.csdn.net/weixin_44840172/article/details/110291330