zoukankan      html  css  js  c++  java
  • 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('
    ')
            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('
    ').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 + '
    ') #锁定用记名写入锁定文件
                    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()

     

    
    
  • 相关阅读:
    Android开发_Animation
    spring开发_JDBC操作MySQL数据库_使用xml配置事务管理
    spring开发_AOP_代理模式
    java file 文件操作 operate file of java
    spring开发_spring构造注入Bean
    spring开发_spring中Bean的作用域_singleton_prototype
    spring开发_JDBC操作MySQL数据库
    java的jxl技术导入Excel
    spring开发_spring环境搭建
    魅族m8开发 step by step(1)(让程序跑起来)
  • 原文地址:https://www.cnblogs.com/ld1977/p/5967597.html
Copyright © 2011-2022 走看看