Job 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
SAMPLE 1:by Liu
Steps:
1. String read into dictionary
User_info ='eric:123456#catherine:098765'user_list= User_info.split ('#')Print(user_list) user_dic={}#Create an empty dictionary forIteminchuser_list:item_list= Item.split (':')#>>> [' Eric ', ' 123456 ', ' Catherine ', ' 098765 ']User_dic[item_list[0]] = item_list[-1]#??? Print(User_dic)
{' Eric ': ' 123456 ', ' Catherine ': ' 098765 '}
2. Reading a string from a file
f = open ('User_info.txt','R') User_info=F.read () f.close () user_list= User_info.split ('#')Print(user_list) user_dic={}#Create an empty dictionary forIteminchuser_list:item_list= Item.split (':')#>>> [' Eric ', ' 123456 ', ' Catherine ', ' 098765 ']User_dic[item_list[0]] = item_list[-1]#Print(User_dic)
3. Main parts of the program
ImportSysuser_info= {'Alex':"123",'Wenwei':'Gdalex'}count=0username= Input ('User name >>>:')ifUsernameinchUser_info:#lock_list = read information about a locked fileLock_list = ['Alex'] ifUser_infoinchlock_list:Print('is locked') Sys.exit ()Else: whileCount < 3: Password= Input ('pwd >>>:') ifPassword = =User_info[username]:Print('login successful, welcome%s'%username) sys.exit ()Else: Count+ = 1ifCount = = 3: Print('be said, please contact the administrator .') Sys.exit ()Else: Print('Wrong password! Please re-enter. and%s Chance .'% (3-count))Else: Print('user name does not exist')
Sample 2:by
Python Basics-Day 1 assignment-login analog Login