• 用户登录,三级菜单


    用户登录

    详细要求:

    1/输入用户名密码
    2/认证成功后显示欢迎信息
    3/输出三次后锁定
    输入的用户名/密码是在存在密码本里的。
    密码输错三次之后,将该用户锁定,下次登陆后任然生效。
    (要创建密码本和锁定用户的菜单)

    先画个思维导图:

    流程控制代码

    # -*- coding:utf-8 -*-
    #!/usr/bin/env python
    # Author:suchagal
    
    import xlrd
    import sys
    
    users_list = []
    password_list = []
    users_get_out_of_line = []
    
    f = xlrd.open_workbook('users_password.xlsx')
    table = f.sheet_by_name(u'Sheet1')
    
    for i in range(table.nrows):
        users_list.append(table.col(0)[i].value)
        password_list.append(table.col(1)[i].value)
    print(users_list,password_list)
    
    f1 = open('users_get_out_of_line.txt','r')
    line = f1.readline()
    users_get_out_of_line = line.split()
    print(users_get_out_of_line)
    
    while True:
        count = 0
        _user = input("username:")
        if _user in users_get_out_of_line:
            print("user locked")
        elif _user in users_list:
            _password = input("password:")
            if _password == password_list[users_list.index(_user)]:
                print("welcome %s login..."% _user)
            else:
                print("password is error")
                while count < 2:
                    count+=1
                    _password_ = input("password again:")
                    if _password_ == password_list[users_list.index(_user)]:
                        print("correct! welcome %s login..." %_user)
                        break
                    elif count == 2:
                        users_get_out_of_line.append(_user)
                        print("your account will be locked")
                        f2 = open('users_get_out_of_line.txt','w+')
                        for ii in range(0,len(users_get_out_of_line)):
                            f2.write(users_get_out_of_line[ii]+"	")
                        f2.close()
                        break
        else:
            print("username is illegal")

    用户密码字典(excel):users_password.xlsx

    违规用户(.txt)users_get_out_of_line.txt

    新建一个就放到python文件同一个目录下就ok了,如:

    三级菜单

    1/三级菜单
    2/可依次选择进入的
    3/所需要的知识点:列表/字典
    详细要求:
    通过b返回上一级,通过q直接退出程序
    省,市,县,(流程图)

    思维导图:

    代码:

    # -*- coding:utf-8 -*-
    #!/usr/bin/env python
    # Author:suchagal
    
    zone = {
        '山东' : {
            '青岛' : ['四方','黄岛','崂山','李沧','城阳'],
            '济南' : ['历城','槐荫','高新','长青','章丘'],
            '烟台' : ['龙口','莱山','牟平','蓬莱','招远']
        },
        '江苏' : {
            '苏州' : ['沧浪','相城','平江','吴中','昆山'],
            '南京' : ['白下','秦淮','浦口','栖霞','江宁'],
            '无锡' : ['崇安','南长','北塘','锡山','江阴'],
            '宿迁' : ['沭阳','泗阳','泗洪','宿豫','宿城']
        },
        '浙江' : {
            '杭州' : ['西湖','江干','下城','上城','滨江'],
            '宁波' : ['海曙','江东','江北','镇海','余姚'],
            '温州' : ['鹿城','龙湾','乐清','瑞安','永嘉']
        },
        '安徽' : {
            '合肥' : ['蜀山','庐阳','包河','经开','新站'],
            '芜湖' : ['镜湖','鸠江','无为','三山','南陵'],
            '蚌埠' : ['蚌山','龙子湖','淮上','怀远','固镇']
        },
        '广东' : {
            '深圳' : ['罗湖','福田','南山','宝安','布吉'],
            '广州' : ['天河','珠海','越秀','白云','黄埔'],
            '东莞' : ['莞城','长安','虎门','万江','大朗']
        }
    }
    #print(zone.keys())
    #print(zone['江苏']['宿迁'])
    #print(zone['江苏'].keys())
    
    
    while True:
        print(zone.keys())
        which_province = input("choice a province:")
        if which_province in zone.keys():
            while True:
                print(zone[which_province].keys())
                which_city = input("choice a city:")
                if which_city in zone[which_province].keys():
                    print(zone[which_province][which_city])
                    while True:
                        which_chioce = input("程序已结束,back返回上一级,quit退出:")
                        if which_chioce == 'back':
                            break
                        elif which_chioce == 'quit':
                            exit()
                        else :
                            print("input error!")
                            continue
                elif which_city == 'back':
                    break
                elif which_city == 'quit':
                    exit()
                else:
                    print("input error,please input again")
                    continue
        elif which_province == 'back':
            continue
        elif which_province == 'quit':
            break
        else:
            print("input error!")
            continue

     这里面有几个知识点,下次更新。

    就写这么多了,送上一句励志英文:

    Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere.
  • 相关阅读:
    javascript 之异常处理try catch finally--05
    javascript 之基本包装类型--04
    javascript 之基本数据类型、引用数据类型区别--02
    javascript 之数据类型--01
    CSS3 object-fit 图像裁剪
    jQuery.extend 使用函数
    ios 不支持iframe 解决方案
    python常用代码积累
    mysql日志类型
    python中列表 元组 字符串如何互相转换
  • 原文地址:https://www.cnblogs.com/suchagal/p/8069939.html
Copyright © 2020-2023  润新知