1 """
2 作业一:编写登陆接口
3 要求:1、输入用户名密码,2、认证成功后显示欢迎信息,3、输入三次后锁定
4 """
5 _username = "aoa"
6 _password = "123"
7 count =0
8 lock = []
9 # 读取黑名单用户
10 f = open(r"D:\Python_work\WeeksPython\day1\lock.txt", "r")
11 file_list = f.readlines()
12 for i in file_list:
13 line=i.strip("\n")
14 lock.append(line)
15
16 username = input("请输入用户名: ").strip()
17
18 # 判断用户是否在黑名单
19 if username in lock:
20 print ("您的账号已锁定,请联系管理员。")
21 else:
22 # 如果用户没有在黑名单,判断用户是否存在
23 if username == _username:
24 while count <3:
25 password = input("请输入密码: ")
26 if username == _username and password == _username:
27 print("健康一体机管理系统欢迎%s!" %username)
28 break
29 else:
30 print("密码输入错误,请重新输入 ")
31 count += 1
32 else:
33 print("密码输入错误次数超过3次,账户被冻结 ")
34 f = open(r"D:\Python_work\WeeksPython\day1\lock.txt", "w+")
35 li = ["%s" %username]
36 f.writelines(li)
37 f.close()
38 else:
39 print("用户名不存在,请输入正确的用户名 ")
1 """
2 作业二:多级菜单
3 要求:1、三级菜单,2、可依次选择进入各子菜单,3、所需新知识点:列表、字典
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 exit_flag = False # 标志位,只要不为True,循环会一直执行
33
34 while not exit_flag:
35 for p in data:
36 print(p)
37 province = input("选择进入省份(按q退出)>>>: ").strip()
38 if province == "q":
39 print("您已退出系统,欢迎下次再用!")
40 break
41 if province in data:
42 while not exit_flag:
43 for c in data[province]:
44 print("\t", c)
45
46 city = input("选择进入城市(按q退出,b返回上一级)>>>: ").strip()
47 if city == "b":
48 break
49 elif city == "q":
50 exit_flag = True
51 print("您已退出系统,欢迎下次再用!")
52 elif city in data[province]:
53 while not exit_flag:
54 for s in data[province][city]:
55 print("\t\t", s)
56
57 spot = input("选择景点>>>: ").strip()
58 if city == "b":
59 break
60 elif city == "q":
61 exit_flag = True
62 print("您已退出系统,欢迎下次再用!")
63 elif spot in data[province][city]:
64 print("您选择的景区:",'\033[34;1m', spot, '\033[0m')
65 exit_flag = True
66 else:
67 print("\033[31;0m对不起!你输入的景区不存在,请重新输入!\033[0m")
68 else:
69 print("\033[31;0m对不起!你输入的地市不存在,请重新输入!\033[0m")
70 else:
71 print("\033[31;0m对不起!你输入的省份不存在,请重新输入!\033[0m")
72
73 # 30:黑,31:红 ,32:绿,33:黄 ,34:蓝色,35:紫色,36:深绿 ,37:白色;
74 # 打印错误信息,并且用红色标注。颜色标识方法:\033[显示方式;前景色;背景色m