python课程第一天作业1-模拟登录

python课程第一天作业1-模拟登录

第一周作业:

作业1:编写登陆接口

  • 输入用户名密码
  • 认证成功后显示欢迎信息
  • 输错三次后锁定

流程图:

代码:后来修改过一次:

#!/usr/bin/env python
# -*-conding:utf-8-**
# __Author__:'liudong'
#!/usr/bin/env python
# -*-coding:utf-8-*-
# __author__="Life"
print('You have three times to login,otherwise your account will be locked!')
for i in range(3):
    username = input('Please input your username:')
    lock_file = open('account_lock.txt', 'r')
    lock_list = lock_file.readlines()  # 已经被锁定用户清单文件
    for lock_line in lock_list:     #判断用户输入的名字是否已经锁定(在锁定的文件列表中)
        lock_line = lock_line.strip('\n')
        if username == lock_line:
            print('Your account is locked!')
            lock_file.close()
            exit()
    user_account=open('user_account.txt','r')
    user_account_list=user_account.readlines()
    #print(user_account_list)
    for user in user_account_list:
        (user_infile,password_infile)=user.strip('\n').split()
        if username == user_infile:
            #print(user_infile)
            j = 0
            while j < 3:
                password = input('Please input your password:')
                if password == password_infile:
                    print('login successed!')
                    user_account.close()
                    lock_file.close()
                    exit()
                else:
                    print('Invalid username or password...')
                    print('this is the %d time(s)' % (j + 1))
                j+=1
            else:
                lock_file = open('account_lock.txt', 'w')
                lock_file.write(username + '\n') #锁定用记名写入锁定文件
                print('Your account is locked! Please,contact adminstrator to unlock your account!')

                exit()
    else:
        print('user %s is not exists,please input again:')

lock_file.close()
user_account.close()

 

 

 
  
posted @ 2016-10-16 20:28 ld1977 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值