• day1作业


    作业一:博客

    作业二:编写登陆接口

    • 输入用户名密码
    • 认证成功后显示欢迎信息
    • 输错三次后锁定
    作业三:多级菜单
    • 三级菜单
    • 可依次选择进入各子菜单
    • 所需新知识点:列表、字典

    作业一分析:

    readme.md

    博客地址:http://www.cnblogs.com/wanghui1991
    执行方式:Linux平台下安装好python3.x以上版本
                   chmod +x login.py
                   ./login.py
    数据:account.db村烦的事锁定的账户信息
    

    login.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    #Author:wanghui
    import os,sys,getpass
    
    #定义变量
    lock_file = 'lock.db'              #锁定用户信息
    account_file = 'account.db'        #正确用户信息
    counter = 0   #初始化计数器
    while counter < 3:
        username = input('please input your name:').strip()
        lock_check = open(lock_file,'r+')
        account_check = open(account_file,'r+')
        for u_line in lock_check.readline():
            u_line = u_line.strip('
    ')
            if username == u_line:
                sys.exit("%s is locked!!" %username)
        password = getpass.getpass('please input your password:')
        for p_line in account_check.readlines():
            user,passwd = p_line.strip('
    ').split()
            if username == user and password == passwd:
                sys.exit('user %s ,welcome to login!!'%username)
            elif username != user:
                sys.exit('username incorrect!!')
            elif username == user and password != passwd:
                print('retry again!!')
                counter += 1
            account_check.close()
    else:
        print('user %s is locked!!'%username)
        lock_now = open(lock_file,'a')
        lock_now.write(username)
        lock_now.write('
    ')
        lock_now.close()
    

      

  • 相关阅读:
    1017 A除以B (20分)**
    剑指 Offer 11. 旋转数组的最小数字(简单)
    剑指 Offer 04. 二维数组中的查找(中等)
    剑指 Offer 53
    剑指 Offer 53
    剑指 Offer 03. 数组中重复的数字(简单)
    剑指 Offer 58
    剑指 Offer 05. 替换空格(简单)
    执行npm install命令出错问题
    剑指 Offer 35. 复杂链表的复制(中等)
  • 原文地址:https://www.cnblogs.com/wanghui1991/p/5968338.html
Copyright © 2020-2023  润新知