python 作业

来源:互联网 发布:知识产权投诉淘宝处罚 编辑:程序博客网 时间:2024/05/05 12:02

作业:创建一个简单的雇员姓名和编号的程序,让用户输入一组雇员姓名和编号,你的程序可以提供姓名排序输入的功能,雇员姓名显示在前面,后面的是对应的雇员编号。附加题:添加一项功能,按照雇员编号的顺序输出数据。



!/usr/bin/env python

#coding:utf-8

dict1={}

dict2={}

def add():

  i=0

  count=input("please input the number of employee:")

  while i<count:

    name=raw_input("please input the name of employee:")

    if name=="--":

     break

    number=raw_input("please input the number of employee:")

    if number==" ":

     break

     dict1[name]=number

     dict2[number]=name

     i+=1

  xuanze()

def xuanze():

         print '''

         1.add the data

         2.sort with name

         3.sort with number

         4.quit  '''

         choose=raw_input("please choose a number:")

         if choose == "1":

             add()

         elif choose == "2":

             for key in sorted(dict1):

                    print key,dict1[key]

        elif choose == "4":
             quit
         else:

             print "error"

             pass
if __name__ == '__main__':
         xuanze




结果:


                                          

0 0
原创粉丝点击