#寫一個產生一批密碼的程序,
#要求密碼長度大於6,必須包含大寫字母、小寫字母、數字和特殊字符
#每次產生的密碼不能重復
# 寫到文件里面
import string,random
list=[]
number=input("請輸入要產生的密碼數量:")
verrify_digit=number.isdigit()
if verrify_digit:
for i in range(int(number)):
UP = string.ascii_uppercase # 大寫字母
a, b = random.sample(UP, 2)
LOW = string.ascii_lowercase # 小寫字母
c, d = random.sample(LOW, 2)
NUM = string.digits # 數字
e, f = random.sample(NUM, 2)
SPE = string.punctuation # 特殊字符
g, h = random.sample(SPE, 2)
passwd = a + b + c + d + e + f + g + h
list.append(passwd)
else:
print("請輸入數字!")
# password=str(set)
s1=set(list)
try:
for i in s1:
f = open('password.txt', 'a+', encoding='utf-8')
f.write(i + '\n')
f.close()
except NameError as e:
print("未輸入數字引起的錯誤",e)