用python写一个查询员工信息,添加员工信息的功能

# coding=utf8


e1 = {'name':'Jack', 'age':22, 'sal':8000}
e2 = {'name':'Tom', 'age':27, 'sal':5000}
e3 = {'name':'Nick', 'age':26, 'sal':8000}
e4 = {'name':'Mary', 'age':21, 'sal':12000}
e5 = {'name':'Lucy', 'age':22, 'sal':3000}
e = [e1, e2, e3, e4, e5]

while True:
    print "1. 添加员工信息"
    print "2. 查询员工信息"
    print "3. 退出程序"
    option = raw_input('请选择[1-->3]: ')
    if option == '1':
        name = raw_input('请输入员工名字:')
        age = input('请输入员工年龄:')
        salary = input('请输入员工工资:')
        e.append({'name':name, 'age':age, 'sal': salary})
        print "添加员工信息成功\n"

    elif option == '2':
        name = raw_input('请输入员工名字:')
        for emp in e:
            if emp['name'].upper() == name.upper():
                # print "名字:%s, 年龄:%d, 工资:%d\n"%(emp['name'], emp['age'], emp['sal'])
                print "名字:%(name)s, 年龄:%(age)d, 工资:%(sal)d\n"%emp
                break
        else:
            print "没有此员工信息\n"
    elif option == '3':
        break
    else:
        print "错误选项"

print "Bye."

你可能感兴趣的:(用python写一个查询员工信息,添加员工信息的功能)