建立cards_main文件:

# _*_ coding:utf-8 _*_
"""
file: cards_main.py
date: 2018-07-18 19:47
author: jiong
desc:"""
import cards_tools
#无限循环,由用户主动决定什么时候退出
while True:
#TODO注释,用于标记需要去做的工作cards_tools.show_menu()action_str = raw_input("请选择希望执行的操作: ")print("你选择的操作是 %s" % action_str)#1,2,3针对名片的操作if action_str in ["1","2","3"]:if action_str == "1":cards_tools.new_card()elif action_str == "2":cards_tools.show_all()elif action_str == "3":cards_tools.search_card()#0退出系统elif action_str == "0":print("欢迎再次使用【名片管理系统】:")break#如果在开发程序时,不希望立刻编写分支内部的代码#可以使用pass关键字,表示一个占位符,能够保证程序的代码结构正确#运行程序时,pass关键字不会执行任何操作else:print("输入错误,请重新输入:")

建立cards_tools文件

# _*_ coding:utf-8 _*_
"""
file: cards_tools.py
date: 2018-07-18 19:47
author: jiong
desc:"""
card_list = []def show_menu():"""显示菜单"""print '*' * 50print '欢迎使用【名片管理系统】'print ''print '1.新增名片'print '2.显示全部'print '3.搜索名片'print '0.退出系统'print '*' * 50def new_card():"""新增名片"""print '-' * 50print '新增名片'# 1.提示用户输入名片的详细信息name_str = raw_input('请输入姓名:')phone_str = raw_input('请输入电话:')qq_str = raw_input('请输入QQ:')email_str = raw_input('请输入邮箱:')# 2.使用用户输入的信息建立一个名片字典card_dict = {'name_str': name_str,'phone_str': phone_str,'qq_str': qq_str,'email_str': email_str}# 3.将名片字典添加到列表中card_list.append(card_dict)  # 把一个字典追加到一个列表中print card_list# 4.提示用户添加成功print '添加%s 的名片成功' % name_strdef show_all():"""显示所有名片"""print '-' * 50print '显示所有名片'# 判断是否存在名片记录,如果没有,提示用户并且返回if len(card_list) == 0:print '当前没有任何的名片记录,请使用新增功能添加名片'# return 可以返回一个函数的执行结果# 下方的代码不会被执行# 如果return后面没有任何的内容,表示会返回到调用函数的位置# 并且不返回任何结果return# 打印表头for name in ["姓名", "电话", "QQ", "邮箱"]:print name,print ''# 打印分隔线print '=' * 50# 遍历名片列表依次输出字典信息for card_dict in card_list:# print card_dictprint '%s\t\t%s\t\t%s\t\t%s' % (card_dict['name_str'],card_dict['phone_str'],card_dict['qq_str'],card_dict['email_str'])def search_card():"""搜索名片"""print '-' * 50print '搜索名片'# 1.提示用户输入要搜索的姓名find_name = raw_input('请输入要搜索的姓名:')# 2.遍历名片列表,查询要搜索的姓名,如果没有找到,需要提示用户for card_dict in card_list:if card_dict['name_str'] == find_name:print '姓名 电话 QQ 邮箱'print '=' * 50print '%s %s %s %s' % (card_dict['name_str'],card_dict['phone_str'],card_dict['qq_str'],card_dict['email_str'])# TODO 针对找到的名片记录执行修改和删除的操作# 在我们的日常编写程序中,如果一个函数的代码太多,阅读和编写都是一件困难的事情,而在开发中,可以针对一个具体独立的功能来封装一个函数,由这个函数来处理具体的操作,这样就能保证每个函数中的代码清晰明了,功能明确deal_card(card_dict)breakelse:print '抱歉,没有找到%s' % find_namedef deal_card(find_dict):print find_dictaction_str = raw_input('请选择要执行的操作 ''[1] 修改 [2] 删除 :')# 替换已经存在的键值对if action_str == '1':find_dict['name_str'] = input_card_info(find_dict['name_str'], '姓名:')find_dict['phone_str'] = input_card_info(find_dict['phone_str'], '电话:')find_dict['qq_str'] = input_card_info(find_dict['qq_str'], 'QQ:')find_dict['email_str'] = input_card_info(find_dict['email_str'], '邮箱:')print '修改名片成功!!!'elif action_str == '2':card_list.remove(find_dict)print '删除名片成功!!!'def input_card_info(dict_value, tip_message):""":param dict_value:字典中原有的值:param tip_message:输入的提示文字:return:如果用户输入了内容,就返回内容,负责返回字典中原有的值"""# 1.提示用户输入内容result_str = raw_input(tip_message)# 2.针对用户的输入进行判断,如果用户输入了内容,直接返回结果if len(result_str) > 0:return result_str# 3.如果用户没有输入内容,返回‘字典中原有的值’else:return dict_value

执行cards_mian文件:



Linux:python示例制作名片相关推荐

  1. python软件代码示例-python 示例代码1

    第一章 python基础一 ​在此不再赘述为什么学习python这门编程,网上搜索一箩筐.我在此仅说一句python的好,用了你就会爱上它. 本python示例代码1000+带你由浅入深的了解pyth ...

  2. python代码示例-python 示例代码1

    第一章 python基础一 ​在此不再赘述为什么学习python这门编程,网上搜索一箩筐.我在此仅说一句python的好,用了你就会爱上它. 本python示例代码1000+带你由浅入深的了解pyth ...

  3. python 示例_带有示例的Python File write()方法

    python 示例 文件write()方法 (File write() Method) write() method is an inbuilt method in Python, it is use ...

  4. python 示例_带有示例的Python文件关闭属性

    python 示例 文件关闭属性 (File closed Property) closed Property is an inbuilt property of File object (IO ob ...

  5. python 示例_带有示例的Python date timetuple()方法

    python 示例 Python date.timetuple()方法 (Python date.timetuple() Method) date.timetuple() method is used ...

  6. python 示例_Python date isoweekday()方法与示例

    python 示例 Python date.isoweekday()方法 (Python date.isoweekday() Method) date.isoweekday() method is u ...

  7. python 示例_带有示例的Python date isocalendar()方法

    python 示例 Python date.isocalendar()方法 (Python date.isocalendar() Method) date.isocalendar() method i ...

  8. python 示例_带有示例的Python字典update()方法

    python 示例 字典update()方法 (Dictionary update() Method) update() method is used to update the dictionary ...

  9. python 示例_带有示例的Python字典popitem()方法

    python 示例 字典popitem()方法 (Dictionary popitem() Method) popitem() method is used to remove random/last ...

最新文章

  1. elasticsearch 客户端工具_1分钟系列-Elasticsearch 简介与单机版安装
  2. 直播回顾 | 数据驱动实践的三大运营场景讲解
  3. 微信几亿人在线的点赞、取消点赞系统,用Redis如何实现?
  4. 【python教程入门学习】学python要多久,0基础学python有多难
  5. jenkins发送邮件
  6. pyecharts显示所有x轴_基于Pyecharts可视化大屏案例一(1)
  7. 动态风云--互联网感言(三)
  8. 统一异常处理ControllerAdvice
  9. 【PM2.5预测】基于matlab灰色模型PM2.5预测【含Matlab源码 499期】
  10. 勘测定界坐标导入cad
  11. Ubuntu16 Nvidia驱动安装(.run文件安装)
  12. 聊聊IT外包公司(外包公司的运作模式和赚钱之道)
  13. JAVA微商城_O2O微门店SAAS系统
  14. SpringCloud-25-Gateway:动态路由、过滤器使用
  15. 工作三年程序员收入到底多高?透露收入:网友:哇,真的好高呀!
  16. ABclonal再添一员“蛋白~DNA互作研究”大将—CUTTag
  17. 定点 浮点 神经网络 量化_神经网络模型量化论文小结
  18. CHIL-SQL-CREATE TABLE 语句
  19. 终于有人总结了图神经网络!
  20. 【RDMA】21. RDMA之内存地址基础知识

热门文章

  1. goland 修改文件的关联类型
  2. 关键字volatile有什么含意 并给出三个不同的例子
  3. 全套人民币(纸币)图片欣赏------你认识多少张?
  4. 神武服务器物品开放,《神武4》电脑版庭院装饰游乐·对弈棋盘限服开放
  5. python画一片树叶
  6. 清华硕士的集体逃离!中科院科研人员自白:我为什么离开北京?
  7. 服务器win7系统镜像文件,win7云服务器镜像
  8. kali linux 命令行设置WIFI
  9. 异闻录——每晚一个离奇故事 敬请期待,一天,一个离奇故事!如果您喜欢,请在评论里发表您的高见,支持,每天一个新故事!
  10. Struts2、Mybatis、Spring整合