#文件
alex,56666,22,Engineer,IT
rain,456,25,Teacher,Teching
#实现以下功能
# 1. 修改个人信息
# 2. 打印个人信息
# 3. 修改密码
choice =''' 1. 修改个人信息 2. 打印个人信息 3. 修改密码 ''' def look(accounts,user): print(''' name:%s age: %s position:%s post:%s'''%(accounts[user][0],accounts[user][2],accounts[user][3],accounts[user][4])) output(accounts,user) def save(accounts_dic): f.seek(0) f.truncate() for k in accounts_dic: row = ','.join(accounts_dic[k]) f.write('%s\n'%row) f.flush() def modify(accounts,user): print(''' %s name:%s %s age: %s %s position:%s %s post:%s'''%(0,accounts[user][0],2,accounts[user][2],3,accounts[user][3],4,accounts[user][4])) number = int(input("请输入修改的序号")) change = input((accounts[user][number])+'修改的值') accounts[user][number] = change print(accounts[user]) save(accounts) output(accounts,user) def passwd(accounts,user): print('当前密码为%s'%(accounts[user][1])) user_pas = input('请输入新的密码') accounts[user][1] = user_pas print('新密码为%s'%user_pas) save(accounts) output(accounts,user) def output(accounts,user): print(choice) num = input('请输入数字选项') if num == '1': modify(accounts,user) elif num == '2': look(accounts,user) elif num == '3': passwd(accounts,user) f_name_new = 'info_new' f_new = open(f_name_new,'w+',encoding='utf-8') f_name = 'info' f = open(f_name,'r+',encoding='utf-8') data = f.readlines() accounts = {} for line in data: line = line.strip() itmes = line.split(',') accounts[itmes[0]] =itmes count =0 while count <3 : user = input('User Name>') if user in accounts.keys(): password = input('Password') if password == accounts[user][1]: print('登陆成功') output(accounts,user) # print(choice) # num = input('请输入数字选项') # if num == '2' : # look(accounts,user) else: count+=1 continue else: count+=1 continue f.close()