您的位置:首页 > 编程语言 > Python开发

python 作业

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

!/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

结果:



                                          
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: