alex教学用例--员工信息表

员工信息:姓名,性别,电话,邮件 存储在文件中

能够通过姓名主要查询,也可以通过电话,邮件查询员工信息

能够更改员工信息

能够添加员工信息

能够删除员工信息

#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()
				
时间: 2024-08-05 21:02:07

alex教学用例--员工信息表的相关文章

Python开发【第xxx篇】函数练习题-----员工信息表

文件存储格式如下: id,name,age,phone,job 1,Alex,22,13651054608,IT 2,Egon,23,13304320533,Tearcher 3,nezha,25,1333235322,IT 现在需要对这个员工信息文件进行增删改查. 基础必做: a.可以进行查询,支持三种语法: select 列名1,列名2,- where 列名条件 支持:大于小于等于,还要支持模糊查找. 示例: select name,age where age>22   #> < s

python基础之员工信息表作业

周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tearcher 3, nezha, 25, 1333235322, IT 现在需要对这个员工信息文件进行增删改查 一. 基础必做: 可以进行查询,支持三种语法: select 列名1,列名2,… where 列名条件 支持:大于小于等于,还要支持模糊查找. 示例: select name, age wh

python3 员工信息表

这是最后一条NLP了......来吧 十二,动机和情绪总不会错,只是行为没有效果而已 动机在潜意识里,总是正面的.潜意识从来不会伤害自己,只会误会的以为某行为可以满足该动机,而又不知道有其他做法的可能. 情绪总是给我们一份推动力,情绪使我们在该事情之中有所学习,学到了,情绪便会消失. 我们可以接受一个人的动机和情绪,同时不接受他的行为. 接受动机和情绪,便是接受那个人,那个人也会感觉出你对他的接受,因而更肯让你去引导他做出改变. 任何一次行为不等于一个人. 行为不能接受,是因为没有效果,找出更好

Python 基础 - Day 4 Assignment - 员工信息表程序

作业要求及初步思路 员工信息表程序,实现增删改查操作: ① 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 select * from staff_table where dept = "IT" select * from staff_table where enroll_date like "2013"② 解决方案: sql语句的python解析问题,即将用户输入的sql

打印简单公司员工信息表

要求,输入name不为空,输入次数最多3次,3次后跳出程序: 知识点: raw_input str转int whil if elif else continue break for 导入模块 引用变量值 格式化输出 vim #!/usr/bin/env python import sys user_name = "carson" this_year = 2014 counter  = 0 while True:     if counter < 3:         name =

python-作业:员工信息表

程序可实现以下功能:1.查询,输入select name,age from staff_table where age > 22,查询到符合要求的信息: 输入select * from staff_table where dept = "IT",查询到符合要求的信息: 输入select * from staff_table where enroll_date like "2013",查询到符合要求的信息.2.创建,输入insert Mickle,22,1365

L01-04:python查询员工信息表练习

#decoding=utf-8 '''编写可供用户查询的员工信息表! 1|用户认证    ID Name department phone    查询关键字:姓名''' import linecache input01=raw_input("pls write your name:") i=1 name=[] count = len(open('user.txt','rU').readlines()) while i<=count:         fline = linecac

Python下用List对员工信息表进行模糊匹配

#需求 用户可以模糊查询员工信息 显示匹配了多少条,匹配字符需要高亮度显示 #脚本内容 #!/usr/bin/env python #_*_ coding:utf-8 _*_ while True:         info = 'info.txt'         f = file(info)         search=raw_input('Please Engter You Search Info: ')         for line in f.readlines():       

员工信息表作业

# 只实现作业要求的查询功能 # 增加,删除,修改功能为选做题 # 创建员工信息表 # 用户输入查询命令 # 分析用户输入的命令,从命令中提取需要查询的关键字 # 根据关键字来查询内容并输出 staff_table=r'F:\python文件\day21生成器\员工信息表.txt' def select(cmd1): #查询功能 with open(staff_table) as f: path=f.readlines() #读出多行赋值给path staff_l=[{ 'staff_id':