Python exercises-generating random passwords by intersection

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.