标签:alex python
员工信息:姓名,性别,电话,邮件 存储在文件中
能够通过姓名主要查询,也可以通过电话,邮件查询员工信息
能够更改员工信息
能够添加员工信息
能够删除员工信息
#coding:UTF-8 import sys f_file = ‘employees.txt‘ f = file(f_file) employee_info = {} for line in f.readlines(): line = line.strip().split() employee_info[line[0]] = line[1:] f.close() while True: print ‘‘‘ 1.query someone 2.add someone 3.delete someone 4.update someone 5.exit ‘‘‘ try: choose = int(raw_input(‘Please input a number your choose:‘).strip()) except: print ‘Please input a valid number‘ continue if choose == 1: info = raw_input(‘Please input some info what you want:‘).strip() if employee_info.has_key(info): print employee_info[info] continue else: mobile_info = [] email_info = [] name_info = [] for line in employee_info.items(): print line line = line.split() mobile_info.append(line[2]) email_info.append(line[3]) name_info.append(line[0]) if info in mobile_info: print employee_info[name_info[mobail_info.index(info)]] elif info in email_info: print employee_info[name_info[email_info.index(info)]] else: print ‘Please a valid info‘ continue if choose == 2: print ‘Please input info what you want add‘ name = raw_input(‘Please input the name:‘).strip() sex = raw_input(‘Please input the sex:‘).strip() phone = raw_input(‘Please input the phone:‘).strip() email = raw_input(‘Please input the email:‘).strip() if employee_info.has_key(name): print ‘the name is already exists,please try like %s2‘ %name continue else: info = name + ‘ ‘ + sex + ‘ ‘ + phone + ‘ ‘ + email f = file(f_file,‘a‘) f.write(‘\n‘) f.write(info) f.close() employee_info[name] = [sex,phone,email] continue if choose == 3: name = raw_input(‘Please input the name you want to delete:‘).strip() if not employee_info.has_key(name): print ‘the name is not exists,please try again‘ %name continue else: del employee_info[name] #不向文件里面写删除信息了,好2 continue if choose == 4: print ‘this function is not support now‘ continue if choose == 5: sys.exit()
标签:alex python
原文地址:http://8588103.blog.51cto.com/8578103/1664170