Day1作业---登录接口及多级菜单

 

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 # Author:Ma Qing
 4 
 5 data = { "山东" :{
 6             "济南" :{
 7                 "济南市" :{
 8                     "市中区" :{},
 9                     "历下区" :{},
10                     "天桥区" :{},
11                     "槐荫区" :{},
12                     "历城区" :{},
13                     "长清区" :{},
14                 },
15                 "章丘市" :{},
16             },
17             "青岛" :{
18                 "青岛市" :{
19                     "市南区" :{},
20                     "市北区" :{},
21                     "城阳区" :{},
22                     "四方区" :{},
23                     "李沧区" :{},
24                     "黄岛区" :{},
25                     "崂山区" :{},
26                 },
27                 "胶南市" :{},
28                 "胶州市" :{},
29                 "平度市" :{},
30                 "莱西市" :{},
31                 "即墨市" :{},
32             },
33             "烟台" :{
34                 "烟台市" : {
35                     "芝罘区" :{},
36                     "莱山区" :{},
37                     "开发区" :{},
38                     "福山区" :{},
39                     "高新区" :{},
40                     "牟平区" :{},
41                 },
42                 "招远市" : {},
43                 "龙口市" : {},
44                 "莱州市" : {},
45                 "蓬莱市" : {},
46             },
47             "潍坊" :{},
48             "淄博" :{},
49             "滨州" :{},
50             "济宁" :{},
51             "枣庄" :{},
52         },
53          "北京" :{},
54          "上海" :{},
55 }
56 exit_flag = False
57 while not exit_flag:
58     for i in data:
59         print(i)
60 
61     choice = input("选择进入>>:")
62     if choice in data:
63         while not exit_flag:
64             for j in data[choice]:
65                 print("\t",j)
66             choice2 = input("选择进入>>:")
67             if choice2 in data[choice]:
68                     while not exit_flag:
69                         for k in data[choice][choice2]:
70                             print("\t",k)
71                         choice3 = input("选择进入3:")
72                         if choice3 in data[choice][choice2]:
73                             for v in data[choice][choice2][choice3]:
74                                 print("\t\t",v)
75                             choice4 = input("最后一层,按b返回!")
76                             if choice4 == "b":
77                                 pass
78                             elif choice4 == "q":
79                                 exit_flag = True
80                         if choice3 == "b":
81                             break
82                         elif choice3 == "q":
83                             exit_flag = True
84             if choice2 == "b":
85                 break
86             elif choice2 == "q":
87                 exit_flag = True
三级菜单初版

 

 

作业一:编写登录接口

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

作业二:多级菜单

  • 三级菜单
  • 可一次选择进入各子菜单
  • 所需新知识点:列表、字典
 1 count = 0
 2 exit_flag = False
 3 _username = input("请输入用户名:")
 4 lock_file = open("account_lock","r+")
 5 lock_list = lock_file.readlines()
 6 for lock_line in lock_list:
 7     if _username == lock_line.strip():      #删除空行
 8        print("账号已被锁定!")
 9        break                                #跳出for。。
10 else:
11      user_file = open("account","r")
12      user_list = user_file.readlines()             #这里要用.readlines()
13      for user_line in user_list:
14          username,password=user_line.split(",")     #分割赋值
15          if _username == username :
16             while not exit_flag:
17                 if count <3:
18                     _password = input("请输入密码:")
19                     if _password == password:
20                         print("登录成功!")
21                         exit_flag = True
22                         break          #终止for循环
23                     else:
24                         print("账号或密码错误,请重新登录!")
25                         count +=1
26                     user_file.close()
27                 else:
28                     print("账号已被锁定")
29                     lock_file.write("\n")
30                     lock_file.write(_username)
31                     exit_flag = True
32          else:
33               print("账号不存在!")
登录接口初版

 

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 # Author:Ma Qing
 4 
 5 data = { "山东" :{
 6             "济南" :{
 7                 "济南市" :{
 8                     "市中区" :{},
 9                     "历下区" :{},
10                     "天桥区" :{},
11                     "槐荫区" :{},
12                     "历城区" :{},
13                     "长清区" :{},
14                 },
15                 "章丘市" :{},
16             },
17             "青岛" :{
18                 "青岛市" :{
19                     "市南区" :{},
20                     "市北区" :{},
21                     "城阳区" :{},
22                     "四方区" :{},
23                     "李沧区" :{},
24                     "黄岛区" :{},
25                     "崂山区" :{},
26                 },
27                 "胶南市" :{},
28                 "胶州市" :{},
29                 "平度市" :{},
30                 "莱西市" :{},
31                 "即墨市" :{},
32             },
33             "烟台" :{
34                 "烟台市" : {
35                     "芝罘区" :{},
36                     "莱山区" :{},
37                     "开发区" :{},
38                     "福山区" :{},
39                     "高新区" :{},
40                     "牟平区" :{},
41                 },
42                 "招远市" : {},
43                 "龙口市" : {},
44                 "莱州市" : {},
45                 "蓬莱市" : {},
46             },
47             "潍坊" :{},
48             "淄博" :{},
49             "滨州" :{},
50             "济宁" :{},
51             "枣庄" :{},
52         },
53          "北京" :{},
54          "上海" :{},
55 }
56 exit_flag = False
57 while not exit_flag:
58     for i in data:
59         print(i)
60 
61     choice = input("选择进入>>:")
62     if choice in data:
63         while not exit_flag:
64             for j in data[choice]:
65                 print("\t",j)
66             choice2 = input("选择进入>>:")
67             if choice2 in data[choice]:
68                     while not exit_flag:
69                         for k in data[choice][choice2]:
70                             print("\t",k)
71                         choice3 = input("选择进入3:")
72                         if choice3 in data[choice][choice2]:
73                             for v in data[choice][choice2][choice3]:
74                                 print("\t\t",v)
75                             choice4 = input("最后一层,按b返回!")
76                             if choice4 == "b":
77                                 pass
78                             elif choice4 == "q":
79                                 exit_flag = True
80                         if choice3 == "b":
81                             break
82                         elif choice3 == "q":
83                             exit_flag = True
84             if choice2 == "b":
85                 break
86             elif choice2 == "q":
87                 exit_flag = True
三级菜单初版

 

转载于:https://www.cnblogs.com/bldly1989/p/6523003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值