1 import getpass 2 import sys 3 f = open('user.db','r') 4 welcome="欢迎来欢乐多购物平台" 5 data = f.read() 6 f.close() 7 user_db_list = [] 8 user_info_list = data.split(' ') 9 print(user_info_list) 10 11 for item in user_info_list: 12 temp = item.split('|') 13 v = { 14 'name': temp[0], 15 'password': temp[1], 16 'number': temp[2], 17 } 18 user_db_list.append(v) 19 print(welcome) 20 p = 0 21 while True: 22 user_name = input('请输入您的账号:') 23 if user_db_list: 24 user_password = input('请输入您的密码:') 25 for index,user_list in enumerate(user_db_list): 26 if user_name == user_list['name'] and int(user_list['number']) < 3: 27 if user_password == user_list['password']: 28 print('欢迎',user_name,'登录我们平台') 29 sys.exit() 30 else: 31 print('账号密码错误,请重新输入') 32 # data_read = open('user.db','r') 33 # 34 # data_write = open('user.db', 'w') 35 # data_write.write() 36 break 37 else: 38 print('您输入的是未注册账号') 39 break 40 p += 1 41 if p == 3: 42 print('你的尝试超过限定次数,已退出') 43 break