作业一:编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
流程图
1 # -*- coding utf-8 -*- 2 # Author:Zwt 3 # 实现登录接口 4 5 count = 0 6 f = open("user.txt", "r").read() 7 lock_f = open("lock.txt", "r").read() 8 9 _username = f.split()[0] # 从用户列表中获取的用户名 10 _password = f.split()[1] # 从用户列表中获取的密码 11 _lockname = lock_f.split()[0] # 从锁定列表中获取的用户名 12 _lockpassword = lock_f.split()[1] # 从锁定列表中获取的用户名 13 14 15 while count < 3: 16 username = input("username:") 17 password = input("password:") 18 if username == _lockname: 19 print("此用户名已被锁定") 20 break 21 if username == _username and password == _password: 22 print("欢迎%s登录成功" % username) 23 break 24 else: 25 print("用户名或密码错误") 26 if count == 2: 27 print("此号码被锁定") 28 lock_f = open("lock.txt", "a") 29 lock_f.write(username + ' ' + password + ' ') 30 lock_f.close() 31 break 32 count = count + 1
作业二:多级菜单
- 三级菜单
- 可依次选择进入各子菜单
- 所需新知识点:列表、字典