# 1, write a password-generating program,
# Number of inputs, the number of times to generate the number of data,
# Require password must contain uppercase letters, lowercase letters and numbers, 8 bits in length, cannot be duplicated
1 Importstring, Random2Num=input ('Please enter a number'). Strip ()3pwds=set () #定义一个空集合4 ifnum.isdigit (): #判断是否为数字5I=06 whileLen (PWDs) <int (num):7Passwd=set (Random.sample (string.ascii_letters+string.digits,8))8set1=set (string.ascii_uppercase). Intersection (PASSWD) #求交集 to determine if there are any uppercase letters in Set19Set2 =set (string.ascii_lowercase). Intersection (passwd)TenSet3 =set (string.digits). Intersection (passwd) One ifSet1 andSet2 andSet3: #非0既真, judging Set1,set2,set3 If all is true, the password contains uppercase letters, lowercase letters, numbers AStr_passwd="'. Join (passwd) +'\ n'#to turn the resulting password into a string - #if str_passwd not in PWDs: - Pwds.add (STR_PASSWD) the #i+=1 -Fw=open ('Pwds.txt','W') - fw.writelines (PWDs) - Else: + Print('you're not typing numbers.')
Python exercises-generating random passwords by intersection