Applications sometimes need to interact with the user in order to continue, such as user login. The use of input is the key to this scenario
Scenario: Users need to enter a user name and password when logging in, if the user failed to login three times the account is locked.
Development: Requires two basic files: 1. User account password 2. Blacklist
#!/usr/bin/env Python3##登陆代码locked=open ("Locked.dat","R") Logon=open ("Logins.dat","R")Print("Welcome to XXX, please enter the user name and password!") Username=input ("Please enter user name:") forLineinchLocked:if(Line.strip () = =username):Print("The account is locked! To unlock please contact the administrator!") Locked.close () exit (0) passwd=input ("Please enter your password:")##验证登陆密码 forTimeinchRange (3): time+=1if(time==3): Print("three opportunities have been exhausted, the account is locked, if you need to unlock please contact the administrator!") Lock=open ("Locked.dat","a") Lock.write (username+"\ n") Lock.close () Logon.close () exit (0) forLineinchlogon:if(Username==line.strip (). Split () [0] andPasswd==line.strip (). Split () [1]): Print("Landing Success!") Logon.close () exit (0) passwd=input ("Please first"+str (time+1) +"Enter Password:")
Python User interaction input