Job Requirements:
Enter User name password
After the success of the certification show drink information
Input error three times after locking
# -*- coding: utf-8 -*-# created by chaimengimport sysretry_limit = 3 #定义输错次数限制retry_count = 0 #定义计数器初始值account_file = ' Account.txt ' #文件变量定义account_lock = ' account_lock.txt ' #文件变量定义while retry_ count < retry_limit: #定义循环条件, when the value of the calculator is less than 3 o'clock, has been circulating file_obj_ Lock = open (Account_lock, "R") #已只读模式打开account_lock文件 account = input ("Please enter user name: ") #提示用户输入用户名 for username in file_obj_lock.readlines (): #使用readlines读取account_lock里的锁定账户 if account == username.strip (): #判断如果输入账户在锁定账户内, then prompt and launch print ("Your account is locked in the list") &Nbsp; sys.exit (2) password = input ("Please enter your password: ") # Prompt user to enter password file_obj_account = open (account_file, "R") # Opened the account file match_flag = False #定义匹配标志位 read-only mode, Determine whether the user name and password are entered correctly according to the matching flag for line in file_obj_account.readlines (): #使用readlines读取account里的账户及密码 user,pwd = Line.strip (). Split () #剥去行收尾的空格, then separate the user name and password based on the space between the user name and password. and assigns a value to the USER,PWD variable if account == user and password == pwd : #判断用户名和密码是否相等, if the match is output cue information, and the matching flag position true print (account + ' successfully matched ') match_flag = true break # Jump out of this time for loop body file_obj_account.close () #关闭account文件 File_obj_lock.close () #关闭account_lock文件 if match_flag == false: #如果匹配标志位为False, the account information error print ("User name or password error") retry_count += 1 #计数器加一 else: print (' Welcome login ') #否则账号信息正确 break #用户登录成功, interrupt while loop Else: print (' Your account is locked! ') f = open (' Account_lock.txt ', ' a ') f.write (' \ n ' + account ) #对输错三次的用户账号进行锁定 f.close ()
This article is from the "9415621" blog, please be sure to keep this source http://9425621.blog.51cto.com/9415621/1899829
Python job----Writing login interface