Old boy Python_12 Period _ first day _homework_ account entry lock

Source: Internet
Author: User

Import SYS #导入系统
User_system = "Super big player" #定义系统名
User_admin = "Andy" #定义管理员
user_name = input ("Please enter user name \ n") #用户输入用户名
Lock_file = open ("Lockfile.txt", ' r+ ') #定义本地锁定文件
Lock_list = Lock_file.readlines () #获取每一行
For Lock_line in Lock_list: #循环lock文件
if user_name = = Lock_line.strip (' \ n '): #去掉换行, if lock, exit directly
Print ("Your account has been locked, please contact the Administrator")
Sys.exit ()
User_file = open ("User.txt", ' R ') #定义用户列表
User_list = User_file.readlines ()
For User_line in User_list: #遍历用户列表
(name,passwd) = User_line.strip (). Split () #分别获取账号和密码
If user_name = = Name: #如果用户名正确
j = 0
While J < 3: #密码不超过3次就不断循环
User_password = input ("Please enter password \ n") #用户输入密码
if passwd = = User_password: #如果密码正确, enter the system
Sys.exit ("entered correctly, will enter%s"%user_system)
Else
If J!=2: #如果密码错误, and try less than 3 times
Print ("User:%s password is wrong, please re-enter, there is%d chance, if the wrong 3 times, will lock the user"% (name,2-j))
J + = 1
Else
Lock_file.write (name + ' \ n ') #如果尝试次数大于等于3次, writes the user to the lock list
Print ("User%s has been tried three times, will lock"%user_name)
Sys.exit ()
Else
Pass
Else
Sys.exit ("User%s does not exist, please contact Administrator%s"% (user_name,user_admin)) #如果用户名不存在, will exit
User_file.close () #关闭user文件
Lock_file.close () #关闭lock文件

Old boy Python_12 Period _ first day _homework_ account entry lock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.