一,博客:

二,编辑登录接口

  1. 输入用户名密码

  2. 认证成功后显示欢迎信息

  3. 输入三次后锁定




三,多级菜单

  1. 三级菜单

  2. 依次选择进入各自子菜单

  3. 所需知识点:列表,字典

  4. 可以随时退出到上一级菜单


作业二:

我自己写的:

#!/usr/bin/env python
#-*-coding=utf-8 -*-
#AUTHOR:duwentao

username = ['duwentao','liuxiaohui']  #存储用户名
password = ['123456','456789']      #存储对应的密码
locking = []        #用于锁定
n = 0       #计算输入了几次
while True:
    UserName = input('请输入用户名:')
    if UserName not in locking:
        if UserName in username:
            PassWord = input('请输入密码:')
            if PassWord == password[username.index(UserName)]:
                print ('登录成功')
                exit()
            else:
                n = n+1
                if n == 3:
                    locking.append(UserName)
                print ('用户名或者密码错误,登录失败')
        else:
            PassWord = input('请输入密码:')
            print ("用户名或者密码错误,登录失败")
    else:
        print ("该用户已被锁定")


运行结果:

1.png


作业三:

我写的:

#!/usr/bin/env python
#-*-coding=utf-8 -*-
#AUTHOR:duwentao

dict = {
    "河南":{
        "商丘":["柘城","虞城"],
        "郑州":["中牟","刘集"]

    },

    "河北":{
        "北京":["廊坊","三沙"],
        "唐山":["哦哦","嗯嗯"]
    }

}

for k in dict:
    print (k)

province = input("请输入要选择的省:")
if province in dict:

    for pro in dict[province]:
        print(pro)
    city = input("请输入要选择的市:")
    if city in dict[province]:
        for c in dict[province][city]:
            print (c)
    else:
        print ("输入有误")
else:
    print ("输入有误")
    exit()


老师写的:

__author__ = "Alex Li"

data = {
    '北京':{
        "昌平":{
            "沙河":["oldboy","test"],
            "天通苑":["链家地产","我爱我家"]
        },
        "朝阳":{
            "望京":["奔驰","陌陌"],
            "国贸":{"CICC","HP"},
            "东直门":{"Advent","飞信"},
        },
        "海淀":{},
    },
    '山东':{
        "德州":{},
        "青岛":{},
        "济南":{}
    },
    '广东':{
        "东莞":{},
        "常熟":{},
        "佛山":{},
    },
}
exit_flag = False

while not exit_flag:
    for i in data:
        print(i)
    choice = input("选择进入1>>:")
    if choice in data:
        while not exit_flag:
            for i2 in data[choice]:
                print("\t",i2)
            choice2 = input("选择进入2>>:")
            if choice2 in data[choice]:
                while not exit_flag:
                    for i3 in data[choice][choice2]:
                        print("\t\t", i3)
                    choice3 = input("选择进入3>>:")
                    if choice3 in data[choice][choice2]:
                        for i4 in data[choice][choice2][choice3]:
                            print("\t\t",i4)
                        choice4 = input("最后一层,按b返回>>:")
                        if choice4 == "b":
                            pass
                        elif choice4 == "q":
                            exit_flag = True
                    if choice3 == "b":
                        break
                    elif choice3 == "q":
                        exit_flag = True
            if choice2 == "b":
                break
            elif choice2 == "q":
                exit_flag = True