Flow chart:
Code:
1 #Author:p J J2 #Create two new files, one called User_lock.txt, one called User.txt, enter the user name and password in user.txt such as: PJJ 123 If more than one user is required, after entering a user3 #Enter a second user4Count=05 whileCount<3:6Username = input ("Please enter user name:")7F1 = open ('User_lock.txt','r+')8Lock_list =F1.readlines ()9 Ten forLock_userinchlock_list: OneLock_user = Lock_user.strip ('\ n') A ifusername==Lock_user: - Print("User%s has been blacklisted. Program Exit"%username) - exit () theF2 = open ("User.txt","R") -File_list =F2.readlines () - forLineinchfile_list: -User,pwd=line.strip ("\ n"). Split () + - ifusername==User: +Count2=0 A whileCount2<3: atPassword=input ("Please enter your password:") - ifpassword==pwd: - Print("Login Successful") - exit () - Else: - ifCount2<2: in Print("Password input Error! , you can also enter%d times"% (2-count2)) -Count2+=1 to Else: +F1.write (username +'\ n') - Print("error entering your password 3 times, your account has entered the blacklist") the exit () * $ Else:Panax Notoginseng ifCount < 2: - Print('the%s entered does not exist and can be entered%d times'% (username, 2-count)) theCount + = 1 + Else: A Print("%s user does not exist, program exits! "%username) the + f1.close () -F2.close ()
Two new. txt files
User name, password, enumerated in User.txt
Python-day1 Writing the Login interface