1. Enter User name Login
2. Display welcome information after successful authentication
3, password error three times after locking
1 #Author BIGD2 ImportOs,sys3 4I=05 whileI<3:6Username = input ("Enter your name:")7 8 #Check if the user exists9Locked_lines = open ("Locked.txt","r+") # #对文件进行读写Ten forLocked_lineinchLocked_lines: One ifUsername = = Locked_line.strip ('\ n'): # #取得姓名 A Print("You are locked,fuck off") - sys.exit (0) - the -Lines = open ("User-passwd.txt","R") # #对文件只读 - forLineinchlines: -[NAME,PASSWD] = Line.strip ('\ n'). Split (' ', 1) # #取得姓名和密码. Strip remove the symbols on both sides, spilt separate + - ifUsername = =Name: + Print("hello,%s"%(name)) A atj=0 - whileJ<3: - Print(passwd) -PD = input ("Enter your Passwrod:") - ifPD = =passwd: - Print("Welcome%s"%(name)) in exit (0) - Else: to Print("Wrong!you has%d times"% (2-j)) + -J + = 1 the Else: *Locked_lines.write (username +'\ n') $ Print("locked")Panax Notoginseng exit (0) - the Else: + Pass A the Else: + Print("You have %d times"% (2-i)) -i + = 1 $ Else: $ Print("user is not exist.bye!")
Small case: Writing a login interface