The first Python code, wrote a day, finally did not error, it is worth remembering.
Basic requirements:
Write a login interface, login three times to lock the user
1. Contains a user information file, user name and password
2. Blacklist file
Process:
1. First check whether the blacklist, if present, do not let the login
2. If not in the blacklist is not in the user list, you are prompted to find the administrator to open
3. If the user table is prompted for a password, if more than three times to enter the password, the user is blacklisted.
Code implementation Flowchart:
#-*-coding:utf-8-*-#author:rxs002 2016-8-1 White= Open ('Whitelist.txt','R') Black= Open ('Blacklist.txt','R') passwd= Open ('Pwdlist.txt','R') NameList=White.read () blacklist=black.read () pwdlist=passwd.read () Namecount=0pwdcount=0totalcount=0#program Start whileTrue:username= Input ('Please enter user name:'). Strip ()#print (namelist)#print (username) ifUsernameinchblacklist:Print('users in the blacklist, please contact the administrator! -----') Print('program because the Blacklist normal end!!! ') Break elifUsernameinchnamelist:pwd= str (Input ('Please enter user password:') . Strip ()ifPwdinchNameList:Print('password is correct, welcome to login! ') Print('The program because the password entered correctly, the normal end!!! ') Break elifPwd not inchNameList: forPwdcountinchRange (0, 3): ifPwdinchNameList:Print('password input is correct, please enter the system!!! ') Break Else: pwd= str (Input ('password is incorrect, please re-enter the password:') . Strip () Pwdcount+ = 1Print('You also have%d chances to enter your password'% (3-Int (pwdcount))) whilePwdcount >= 3: Print('password input more than three times, the account is locked, please contact the administrator to deal with! ') black.close () Black1= Open ('Blacklist.txt','a') Black1.write (username) black1.write ('\ n') Black1.close () Break Break Else: Print('user does not exist, please contact administrator to create user!!! ') Breakwhite.close () black.close () Passwd.close ( )
View Code
Python login, enter password three times