The user has three chances to log in, log in successfully, display the Welcome screen.
Three login failed, account locked, next logon failed.
Ideas:
1: Process Control: For or while loop, up to three detection purposes.
2: File operation.
Detect the document, once the input account name is found in the locked document, display lock, Login failed.
First time without optimized version code:
#_ *_coding:utf-8_*_times = 0 # initial number of 0Username = "Wuqiangroy" UserPassword = "123321" f = open ("Aaa.txt", "R") # Open AA in read mode a.txt files, if not created automatically. File_list = F.readlines () f.close () lock = [] #lock为一个列表. For i in file_list:line = I.strip ("\ n") lock.append (line) Else:while times < 3:username = Raw_input (" Please enter the username: ") if username in Lock: #检测输入帐户名是否在lock中, if the display account is locked, then break jumps out of the loop. Print "You have been locked!" Break password = raw_input ("Please enter your password:") if username = = Username and password = USERPASSW Ord:print "successfull! Welcome Log in! " Break Else:print "Your username or password is wrong! Please enter again! "Times + = 1 print" You just has only%s shots! "% (3-times) Else:print" The only 3 time s you used out and the account has been locked! " f = open ("Aaa.txt", "w+") #以写入模式打开aaa. txt file f.write ("\ n") F.write (username) #三次机会输入错误 to write the entered name into the Aaa.txt file. F.close ()
Python Job 1