1 import datetime 2 # 1、 3 f = open('users') 4 result = f.read() 5 f.close() 6 user_list = result.split() # 7 user_dic = {} 8 for user in user_list: 9 username,password = user.split(',') 10 user_dic[username] = password 11 12 13 14 for i in range(3): 15 username = input('请输入用户名:').strip() 16 # password = getpass.getpass('请输入密码:').strip() 17 password = input('请输入密码:').strip() 18 if username == '' or password == '': 19 print('账号/密码不能为空') 20 elif username not in user_dic: 21 print('用户名不存在') 22 elif password == user_dic.get(username): 23 print('%s欢迎登陆,今天的日期是%s'%(username,datetime.datetime.today())) 24 break 25 else: 26 print('账号/密码错误!') 27 else: 28 print('错误次数过多!')