Simulation Landing Operation Requirements:
1. User input account password to login
2. The user information is saved in the file
3. User password input error three times after locking the user
Additional implementation Features:
1. Prompt for number of input errors
2. Enter the locked user will prompt
3. User does not exist will prompt
Save the user name password in the correct user information file as a dictionary:
{' name ': ' Password ', ' cx ': ' 123 ', ' even ': ' 456 ', ' Test ': ' OK '}
Lock the locked user name as a list in the locked user information file:
[' Name ']
Flow chart:
Detail code: (python3.6)
#!/usr/bin/env python#-*-coding:utf-8-*-#Author:evenCount= 0#to record the number of times a 3 input error is avoided in a requirement, the count item assigns an initial valueLoad = True#to exit after completing the function, assign the initial valueFile = Open ("correct user information file",'R', encoding='Utf-8')#Open the correct user information document for the correct user name passwordFile_wrong = open ("Lock user information files",'r+', encoding='Utf-8')#Open a locked user information document for a locked user name passwordLine = eval (File.readline ())#converts a string in the correct information to a dictionary (the original string is in a dictionary format)Line_wrong = eval (File_wrong.readline ())#converts a string in the correct information to a list (the original string is in list format)defOut ():#Duplicate code definition, function to help jump out while loop and close open document GlobalLoad#declaring global VariablesLoad = False#assign load, in order to jump out of the while loopFile_wrong.close ()#Close the correct user information documentFile.close ()#Close the Lock user information document whileLoad#determine if the feature has been completedName = input ("Please enter user name:")#Enter user namePassword = input ("Please enter your password:")#Enter Password ifNameinchLine andName not inchLine_wrong:#determine if the user name is correct, and whether it is locked whileCount <= 3:#determine if it has been looped 3 times ifPassword = = Line[name]:#determine if the user name corresponds to the correct password Print("you have successfully logged in")#Output Successful login informationOut ()#calling the custom out method Break #jump out of this cycle Else:#description did not enter the correct passwordCount +=1#count items from add oneMsg_count =" "First%s password input error \ n" "% (count)#prompt to enter the number of errors Print(Msg_count)#Print Error count information ifCount < 3:#less than three error inputs, can be re-enteredPassword = input ("password is wrong, please re-enter the password:")#re-enter password elifCount = = 3:#determine if you have lost three times Print("3 errors have been lost and the account is locked")#Print Lock Tip informationLine_wrong.append (name)#Add locked information to a locked tupleFile_wrong.seek (0)#The input pointer moves to the beginning and will result in multiple tuples if not movedFile_wrong.write (str (line_wrong))#Write lock InformationFile_wrong.tell ()#gets the current input pointer position, which produces multiple tuples if not obtainedOut ()#call out Method Break elifNameinchLine_wrong:#determine if the user name is in a locked user name Print("the user name has been locked")#Print locked Notification informationOut ()#calling the custom out method Break #Jump out of the current loop Else:#indicates that the user name is not in the correct user name information Print("the user name does not exist")#Print User name Enter an error messageOut ()#call out Method
View Code
Python jobs: Analog Landing (first week)