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
结果:
!/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
结果:
相关文章推荐
- Coding the Matrix作业Python Lab及提交方法
- 用Python实现一个细粒度hadoop作业监控分析工具
- An Introduction to Interactive Programming in Python 第六课作业 Blackjack
- Python 显示LinkedIn用户作业
- python基础学习小作业(一)
- Python学习第五周:字符串 - 作业20150611
- An Introduction to Interactive Programming in Python 最后的作业 -- 太空战机
- python__博客网络爬虫作业回顾
- 程序设计入门—Python之第二周作业
- Hadoop运行python作业时的依赖于其他库的问题
- python 教程 第十四章、 地址薄作业
- python小作业初版之信用卡交易
- An Introduction to Interactive Programming in Python 第五课作业 memory
- [Python]这次的Python作业
- python 教程 第十四章、 地址薄作业
- 有效使用Python完成信息论作业
- python 教程 第十四章、 地址薄作业
- python学习:程序控制结构·作业20141219
- logistic回归与牛顿方法的python实现 (standford公开课程小作业)
- 马哥linux+python――2015年8月27日课程作业